Formatted according to eslint

This commit is contained in:
Maximilian Giller 2021-01-03 12:31:24 +01:00
parent 444acaf046
commit a2473bd06d
6 changed files with 388 additions and 393 deletions

View file

@ -1,22 +1,21 @@
<template>
<form @submit="submitForm">
<b-input-group id="form">
<b-form-input
<form @submit="submitForm">
<b-input-group id="form">
<b-form-input
id="name"
v-model="form.name"
placeholder="Project name"
trim
>
</b-form-input>
<b-input-group-append>
<b-button variant="outline-secondary" type="submit" :disabled="working">
<b-spinner v-if="working" small />
Add project
</b-button>
</b-input-group-append>
</b-input-group>
</form>
>
</b-form-input>
<b-input-group-append>
<b-button variant="outline-secondary" type="submit" :disabled="working">
<b-spinner v-if="working" small />
Add project
</b-button>
</b-input-group-append>
</b-input-group>
</form>
</template>
<script>
@ -27,7 +26,7 @@ export default {
data() {
return {
form: {
name: ""
name: ""
},
working: false
};
@ -49,16 +48,17 @@ export default {
// Try to login
store
.dispatch("addProject", {
name: this.form.name,
name: this.form.name
})
.then(() => {
this.form.name = "";
this.working = false;
}).catch((e) => {
console.log(e);
this.working = false;
this.form.name = "";
this.working = false;
})
.catch(e => {
console.log(e);
this.working = false;
});
return false;
}

View file

@ -1,61 +1,61 @@
<template>
<b-table
:items="records"
hover
:busy="isLoading"
:fields="fields"
sort-by="start"
:sort-desc="sortDesc"
>
<template #table-busy>
<div class="text-center">
<b-spinner></b-spinner>
</div>
</template>
<b-table
:items="records"
hover
:busy="isLoading"
:fields="fields"
sort-by="start"
:sort-desc="sortDesc"
>
<template #table-busy>
<div class="text-center">
<b-spinner></b-spinner>
</div>
</template>
<!-- Custom data -->
<template #cell(project)="data">
{{ getProject(data.item.project_id).name }}
</template>
<!-- Custom data -->
<template #cell(project)="data">
{{ getProject(data.item.project_id).name }}
</template>
<template #cell(start)="data">
{{ data.item.start_time }}
</template>
<template #cell(start)="data">
{{ data.item.start_time }}
</template>
<template #cell(duration)="data">
{{ getDurationTimestamp(data.item.duration) }}
</template>
<template #cell(duration)="data">
{{ getDurationTimestamp(data.item.duration) }}
</template>
<template #cell(details)="data">
<b-button
size="sm"
@click="() => detailsRecord(data.item.record_id)"
variant="outline-dark"
>
<b-icon class="icon-btn" icon="gear" />
</b-button>
</template>
<template #cell(details)="data">
<b-button
size="sm"
@click="() => detailsRecord(data.item.record_id)"
variant="outline-dark"
>
<b-icon class="icon-btn" icon="gear" />
</b-button>
</template>
<template #cell(abort)="data">
<b-button
size="sm"
@click="() => abortRecord(data.item.record_id)"
variant="outline-primary"
>
<b-icon class="icon-btn" icon="x" />
</b-button>
</template>
<template #cell(abort)="data">
<b-button
size="sm"
@click="() => abortRecord(data.item.record_id)"
variant="outline-primary"
>
<b-icon class="icon-btn" icon="x" />
</b-button>
</template>
<template #cell(stop)="data">
<b-button
size="sm"
@click="stopRecord(data.item.record_id)"
variant="outline-success"
>
<b-icon class="icon-btn" icon="check" />
</b-button>
</template>
</b-table>
<template #cell(stop)="data">
<b-button
size="sm"
@click="stopRecord(data.item.record_id)"
variant="outline-success"
>
<b-icon class="icon-btn" icon="check" />
</b-button>
</template>
</b-table>
</template>
<script>
@ -63,92 +63,92 @@ import store from "@/store";
import { helperService } from "@/services/helper.service.js";
export default {
name: "JugglRecordsList",
props: {
records: {
required: true,
type: Array
},
sortDesc: {
required: false,
type: Boolean,
default: false,
},
running: {
required: false,
type: Boolean,
default: false,
},
name: "JugglRecordsList",
props: {
records: {
required: true,
type: Array
},
data() {
return {
iconScale: 1.6,
requiredFields: [
{
key: "project",
label: "Project",
},
{
key: "start",
label: "Start",
},
{
key: "duration",
label: "Duration",
},
{
key: "details",
label: "Details",
},
],
runningFields: [
{
key: "abort",
label: "Abort",
},
{
key: "stop",
label: "Stop",
},
],
};
sortDesc: {
required: false,
type: Boolean,
default: false
},
computed: {
isLoading: function() {
return this.records === undefined;
running: {
required: false,
type: Boolean,
default: false
}
},
data() {
return {
iconScale: 1.6,
requiredFields: [
{
key: "project",
label: "Project"
},
fields: function() {
var fields = this.requiredFields;
if (this.running) {
fields = [...fields, ...this.runningFields];
}
return fields;
{
key: "start",
label: "Start"
},
{
key: "duration",
label: "Duration"
},
{
key: "details",
label: "Details"
}
],
runningFields: [
{
key: "abort",
label: "Abort"
},
{
key: "stop",
label: "Stop"
}
]
};
},
computed: {
isLoading: function() {
return this.records === undefined;
},
methods: {
getDurationTimestamp: helperService.getDurationTimestamp,
getProject: function(id) {
var project = store.getters.getProjectById(id);
fields: function() {
var fields = this.requiredFields;
if (project === undefined) {
return {};
}
if (this.running) {
fields = [...fields, ...this.runningFields];
}
return project;
},
stopRecord: function(id) {
store.dispatch("endRecord", id);
},
abortRecord: function(id) {
store.dispatch("removeRecord", id);
},
detailsRecord: function(id) {
return id;
// this.$router.push("/record/" + id);
},
return fields;
}
},
methods: {
getDurationTimestamp: helperService.getDurationTimestamp,
getProject: function(id) {
var project = store.getters.getProjectById(id);
if (project === undefined) {
return {};
}
return project;
},
stopRecord: function(id) {
store.dispatch("endRecord", id);
},
abortRecord: function(id) {
store.dispatch("removeRecord", id);
},
detailsRecord: function(id) {
return id;
// this.$router.push("/record/" + id);
}
}
};
</script>

View file

@ -54,7 +54,7 @@ export const jugglService = {
});
},
getRecords({ limit = undefined, finished = undefined}) {
getRecords({ limit = undefined, finished = undefined }) {
var payload = {};
if (limit !== undefined && limit > 0) {

View file

@ -1,244 +1,240 @@
import { jugglService } from "@/services/juggl.service.js";
export const juggl = {
state: {
apiUrl: "https://juggl.giller.dev/api",
projects: {},
records: {},
user: undefined,
auth: undefined,
usingFinishedRecords: false,
usingRunningRecords: false,
usingProjects: false,
recordsLimit: 0,
state: {
apiUrl: "https://juggl.giller.dev/api",
projects: {},
records: {},
user: undefined,
auth: undefined,
usingFinishedRecords: false,
usingRunningRecords: false,
usingProjects: false,
recordsLimit: 0
},
mutations: {
setKey(state, key) {
state.key = key;
},
mutations: {
setKey(state, key) {
state.key = key;
},
setProjects(state, projects) {
state.projects = projects;
},
setRecords(state, records) {
state.records = records;
},
usingFinishedRecords(state, using) {
state.usingFinishedRecords = using;
},
usingRunningRecords(state, using) {
state.usingRunningRecords = using;
},
usingProjects(state, using) {
state.usingProjects = using;
},
setRecordsLimit(state, limit) {
state.recordsLimit = limit;
},
setUser(state, user) {
state.user = user;
},
logout(state) {
state.auth = undefined;
localStorage.removeItem("apiKey");
localStorage.removeItem("userId");
},
login(state, { apiKey, userId }) {
state.auth = { apiKey: apiKey, userId: userId };
localStorage.setItem("apiKey", apiKey);
localStorage.setItem("userId", userId);
},
setProjects(state, projects) {
state.projects = projects;
},
getters: {
runningRecords: (state) => {
return Object.values(state.records).filter(
(record) => record.running
);
},
finishedRecords: (state) => {
return Object.values(state.records).filter(
(record) => !record.running
);
},
auth: (state) => state.auth,
apiUrl: (state) => state.apiUrl,
user: (state) => state.user,
isLoggedIn: (state) => !!state.auth,
records: (state) => state.records,
projects: (state) => state.projects,
projectIds: (state) => {
var projectIds = [];
Object.values(state.projects).forEach((project) => {
projectIds.push(project.project_id);
});
return projectIds;
},
runningProjectIds: (state, getters) => {
var runningProjectIds = [];
Object.values(getters.runningRecords).forEach((record) => {
var projectId = record.project_id;
if (runningProjectIds.includes(runningProjectIds) === false) {
runningProjectIds.push(projectId);
}
});
return runningProjectIds;
},
finishedProjectIds: (state, getters) => {
var runningProjectIds = getters.runningProjectIds;
return getters.projectIds.filter(
(id) => !runningProjectIds.includes(id)
);
},
finishedProjects: (state, getters) => {
var ids = getters.finishedProjectIds;
return Object.values(state.projects).filter((project) =>
ids.includes(project.project_id)
);
},
runningProjects: (state, getters) => {
var ids = getters.runningProjectIds;
return Object.values(state.projects).filter((project) =>
ids.includes(project.project_id)
);
},
getProjectById: (state, getters) => (id) => {
return Object.values(getters.projects).find(
(project) => project.project_id === id
);
},
getRecordById: (state, getters) => (id) => {
return Object.values(getters.records).find(
(record) => record.record_id === id
);
},
setRecords(state, records) {
state.records = records;
},
actions: {
loadProjects({ commit }) {
return jugglService.getProjects().then((r) => {
commit("setProjects", r.data.projects);
commit("usingProjects", true);
});
},
loadUser({ commit }) {
return jugglService
.getUser()
.catch(() => {
return false;
})
.then((r) => {
commit("setUser", r.data.users[0]);
return true;
});
},
loadRecords({ commit, state }, { limit, finished }) {
commit("setRecordsLimit", limit);
return jugglService.getRecords({ limit: state.recordsLimit, finished: finished }).then((r) => {
commit("setRecords", r.data.records);
commit("usingFinishedRecords", true);
commit("usingRunningRecords", true);
});
},
loadRunningRecords({ commit, getters }) {
return jugglService.getRunningRecords().then((r) => {
var allRecords = {
...getters.finishedRecords,
...r.data.records,
};
commit("setRecords", allRecords);
commit("usingRunningRecords", true);
});
},
login({ commit, getters }, { userId, apiKey }) {
// Is already logged in?
if (getters.isLoggedIn) {
this.dispatch("logout");
}
commit("login", { apiKey: apiKey, userId: userId });
return this.dispatch("loadUser")
.catch(() => {
this.dispatch("logout");
return false;
})
.then((r) => {
if (r === false) {
this.dispatch("logout");
return false;
} else {
return true;
}
});
},
logout({ commit }) {
commit("setUser", undefined);
commit("logout");
},
endRecord(context, recordId) {
return jugglService
.endRecord(recordId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
addProject(context, { name }) {
return jugglService
.addProject(name)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
startRecord(context, projectId) {
return jugglService
.startRecord(projectId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
removeRecord(context, recordId) {
return jugglService
.removeRecord(recordId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
updateState({ state }) {
if (state.usingProjects) {
this.dispatch("loadProjects");
}
if (state.usingRunningRecords && state.usingFinishedRecords) {
this.dispatch("loadRecords");
} else if (state.usingRunningRecords) {
this.dispatch("loadRunningRecords");
}
if (state.user === undefined) {
this.dispatch("loadUser");
}
},
loadSavedLogin({ commit }) {
var userId = localStorage.getItem("userId");
var apiKey = localStorage.getItem("apiKey");
if (userId === undefined || apiKey === undefined) {
return;
}
commit("login", { apiKey: apiKey, userId: userId });
},
usingFinishedRecords(state, using) {
state.usingFinishedRecords = using;
},
usingRunningRecords(state, using) {
state.usingRunningRecords = using;
},
usingProjects(state, using) {
state.usingProjects = using;
},
setRecordsLimit(state, limit) {
state.recordsLimit = limit;
},
setUser(state, user) {
state.user = user;
},
logout(state) {
state.auth = undefined;
localStorage.removeItem("apiKey");
localStorage.removeItem("userId");
},
login(state, { apiKey, userId }) {
state.auth = { apiKey: apiKey, userId: userId };
localStorage.setItem("apiKey", apiKey);
localStorage.setItem("userId", userId);
}
},
getters: {
runningRecords: state => {
return Object.values(state.records).filter(record => record.running);
},
finishedRecords: state => {
return Object.values(state.records).filter(record => !record.running);
},
auth: state => state.auth,
apiUrl: state => state.apiUrl,
user: state => state.user,
isLoggedIn: state => !!state.auth,
records: state => state.records,
projects: state => state.projects,
projectIds: state => {
var projectIds = [];
Object.values(state.projects).forEach(project => {
projectIds.push(project.project_id);
});
return projectIds;
},
runningProjectIds: (state, getters) => {
var runningProjectIds = [];
Object.values(getters.runningRecords).forEach(record => {
var projectId = record.project_id;
if (runningProjectIds.includes(runningProjectIds) === false) {
runningProjectIds.push(projectId);
}
});
return runningProjectIds;
},
finishedProjectIds: (state, getters) => {
var runningProjectIds = getters.runningProjectIds;
return getters.projectIds.filter(id => !runningProjectIds.includes(id));
},
finishedProjects: (state, getters) => {
var ids = getters.finishedProjectIds;
return Object.values(state.projects).filter(project =>
ids.includes(project.project_id)
);
},
runningProjects: (state, getters) => {
var ids = getters.runningProjectIds;
return Object.values(state.projects).filter(project =>
ids.includes(project.project_id)
);
},
getProjectById: (state, getters) => id => {
return Object.values(getters.projects).find(
project => project.project_id === id
);
},
getRecordById: (state, getters) => id => {
return Object.values(getters.records).find(
record => record.record_id === id
);
}
},
actions: {
loadProjects({ commit }) {
return jugglService.getProjects().then(r => {
commit("setProjects", r.data.projects);
commit("usingProjects", true);
});
},
loadUser({ commit }) {
return jugglService
.getUser()
.catch(() => {
return false;
})
.then(r => {
commit("setUser", r.data.users[0]);
return true;
});
},
loadRecords({ commit, state }, { limit, finished }) {
commit("setRecordsLimit", limit);
return jugglService
.getRecords({ limit: state.recordsLimit, finished: finished })
.then(r => {
commit("setRecords", r.data.records);
commit("usingFinishedRecords", true);
commit("usingRunningRecords", true);
});
},
loadRunningRecords({ commit, getters }) {
return jugglService.getRunningRecords().then(r => {
var allRecords = {
...getters.finishedRecords,
...r.data.records
};
commit("setRecords", allRecords);
commit("usingRunningRecords", true);
});
},
login({ commit, getters }, { userId, apiKey }) {
// Is already logged in?
if (getters.isLoggedIn) {
this.dispatch("logout");
}
commit("login", { apiKey: apiKey, userId: userId });
return this.dispatch("loadUser")
.catch(() => {
this.dispatch("logout");
return false;
})
.then(r => {
if (r === false) {
this.dispatch("logout");
return false;
} else {
return true;
}
});
},
logout({ commit }) {
commit("setUser", undefined);
commit("logout");
},
endRecord(context, recordId) {
return jugglService
.endRecord(recordId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
addProject(context, { name }) {
return jugglService
.addProject(name)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
startRecord(context, projectId) {
return jugglService
.startRecord(projectId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
removeRecord(context, recordId) {
return jugglService
.removeRecord(recordId)
.catch(() => {
return false;
})
.then(() => {
this.dispatch("updateState");
return true;
});
},
updateState({ state }) {
if (state.usingProjects) {
this.dispatch("loadProjects");
}
if (state.usingRunningRecords && state.usingFinishedRecords) {
this.dispatch("loadRecords");
} else if (state.usingRunningRecords) {
this.dispatch("loadRunningRecords");
}
if (state.user === undefined) {
this.dispatch("loadUser");
}
},
loadSavedLogin({ commit }) {
var userId = localStorage.getItem("userId");
var apiKey = localStorage.getItem("apiKey");
if (userId === undefined || apiKey === undefined) {
return;
}
commit("login", { apiKey: apiKey, userId: userId });
}
}
};

View file

@ -10,7 +10,7 @@
<JugglProjectsPanel :projects="finishedProjects" />
</div>
<div id="add-project-form">
<FormProjectAdd/>
<FormProjectAdd />
</div>
</section>
<section v-if="finishedRecords.length > 0">

View file

@ -1,8 +1,8 @@
<template>
<LayoutNavbarPrivate title="Record details" :center="loading || !!error">
<b-spinner v-if="loading" center />
<p class="danger" v-if="error">{{error}}</p>
<FormRecordDetails :record="record" v-if="record !== undefined"/>
<p class="danger" v-if="error">{{ error }}</p>
<FormRecordDetails :record="record" v-if="record !== undefined" />
</LayoutNavbarPrivate>
</template>
@ -39,5 +39,4 @@ export default {
};
</script>
<style lang="sass">
</style>
<style lang="sass"></style>