|
|
@ -1,7 +1,7 @@ |
|
|
|
import { getField, updateField } from "vuex-map-fields"; |
|
|
|
import { getField, updateField } from "vuex-map-fields" |
|
|
|
import remove from "lodash/remove"; |
|
|
|
import remove from "lodash/remove" |
|
|
|
import SubmissionError from "../../error/SubmissionError"; |
|
|
|
import SubmissionError from "../../error/SubmissionError" |
|
|
|
import isEmpty from "lodash/isEmpty"; |
|
|
|
import isEmpty from "lodash/isEmpty" |
|
|
|
|
|
|
|
|
|
|
|
const initialState = () => ({ |
|
|
|
const initialState = () => ({ |
|
|
|
allIds: [], |
|
|
|
allIds: [], |
|
|
@ -20,27 +20,27 @@ const initialState = () => ({ |
|
|
|
course: null, |
|
|
|
course: null, |
|
|
|
session: null, |
|
|
|
session: null, |
|
|
|
recents: [], |
|
|
|
recents: [], |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const handleError = (commit, e) => { |
|
|
|
const handleError = (commit, e) => { |
|
|
|
console.log("handleError"); |
|
|
|
console.log("handleError") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
console.log(e); |
|
|
|
console.log(e) |
|
|
|
if (e instanceof SubmissionError) { |
|
|
|
if (e instanceof SubmissionError) { |
|
|
|
console.log("SubmissionError"); |
|
|
|
console.log("SubmissionError") |
|
|
|
commit(ACTIONS.SET_VIOLATIONS, e.errors); |
|
|
|
commit(ACTIONS.SET_VIOLATIONS, e.errors) |
|
|
|
// eslint-disable-next-line
|
|
|
|
// eslint-disable-next-line
|
|
|
|
commit(ACTIONS.SET_ERROR, e.errors._error); |
|
|
|
commit(ACTIONS.SET_ERROR, e.errors._error) |
|
|
|
|
|
|
|
|
|
|
|
return Promise.reject(e); |
|
|
|
return Promise.reject(e) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
console.log("ACTIONS.SET_ERROR"); |
|
|
|
console.log("ACTIONS.SET_ERROR") |
|
|
|
// eslint-disable-next-line
|
|
|
|
// eslint-disable-next-line
|
|
|
|
commit(ACTIONS.SET_ERROR, e.message); |
|
|
|
commit(ACTIONS.SET_ERROR, e.message) |
|
|
|
|
|
|
|
|
|
|
|
return Promise.reject(e); |
|
|
|
return Promise.reject(e) |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const ACTIONS = { |
|
|
|
export const ACTIONS = { |
|
|
|
ADD: "ADD", |
|
|
|
ADD: "ADD", |
|
|
@ -64,22 +64,22 @@ export const ACTIONS = { |
|
|
|
ADD_COURSE: "ADD_COURSE", |
|
|
|
ADD_COURSE: "ADD_COURSE", |
|
|
|
ADD_SESSION: "ADD_SESSION", |
|
|
|
ADD_SESSION: "ADD_SESSION", |
|
|
|
REMOVE_SESSION: "REMOVE_SESSION", |
|
|
|
REMOVE_SESSION: "REMOVE_SESSION", |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default function makeCrudModule({ normalizeRelations = (x) => x, resolveRelations = (x) => x, service } = {}) { |
|
|
|
export default function makeCrudModule({ normalizeRelations = (x) => x, resolveRelations = (x) => x, service } = {}) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
actions: { |
|
|
|
actions: { |
|
|
|
checkResponse(response) { |
|
|
|
checkResponse(response) { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return response; |
|
|
|
return response |
|
|
|
}, |
|
|
|
}, |
|
|
|
createWithFormData: ({ commit }, values) => { |
|
|
|
createWithFormData: ({ commit }, values) => { |
|
|
|
console.log("createWithFormData"); |
|
|
|
console.log("createWithFormData") |
|
|
|
commit(ACTIONS.SET_ERROR, ""); |
|
|
|
commit(ACTIONS.SET_ERROR, "") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
service |
|
|
|
service |
|
|
@ -91,58 +91,58 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
} |
|
|
|
} |
|
|
|
})*/ |
|
|
|
})*/ |
|
|
|
.then((data) => { |
|
|
|
.then((data) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD, data); |
|
|
|
commit(ACTIONS.ADD, data) |
|
|
|
commit(ACTIONS.SET_CREATED, data); |
|
|
|
commit(ACTIONS.SET_CREATED, data) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
); |
|
|
|
) |
|
|
|
}, |
|
|
|
}, |
|
|
|
create: ({ commit }, values) => { |
|
|
|
create: ({ commit }, values) => { |
|
|
|
console.log("crud.js create"); |
|
|
|
console.log("crud.js create") |
|
|
|
console.log(values); |
|
|
|
console.log(values) |
|
|
|
commit(ACTIONS.SET_ERROR, ""); |
|
|
|
commit(ACTIONS.SET_ERROR, "") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.create(values) |
|
|
|
.create(values) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((data) => { |
|
|
|
.then((data) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD, data); |
|
|
|
commit(ACTIONS.ADD, data) |
|
|
|
commit(ACTIONS.SET_CREATED, data); |
|
|
|
commit(ACTIONS.SET_CREATED, data) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
del: ({ commit }, item) => { |
|
|
|
del: ({ commit }, item) => { |
|
|
|
console.log("del"); |
|
|
|
console.log("del") |
|
|
|
commit(ACTIONS.SET_ERROR, ""); |
|
|
|
commit(ACTIONS.SET_ERROR, "") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.del(item) |
|
|
|
.del(item) |
|
|
|
.then(() => { |
|
|
|
.then(() => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.SET_DELETED, item); |
|
|
|
commit(ACTIONS.SET_DELETED, item) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
delMultiple: ({ commit }, items) => { |
|
|
|
delMultiple: ({ commit }, items) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
const promises = items.map(async (item) => { |
|
|
|
const promises = items.map(async (item) => { |
|
|
|
const result = await service.del(item); |
|
|
|
const result = await service.del(item) |
|
|
|
|
|
|
|
|
|
|
|
commit(ACTIONS.SET_DELETED_MULTIPLE, item); |
|
|
|
commit(ACTIONS.SET_DELETED_MULTIPLE, item) |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result |
|
|
|
}); |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
return Promise.all(promises).then(() => { |
|
|
|
return Promise.all(promises).then(() => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
findAll: ({ commit, state }, params) => { |
|
|
|
findAll: ({ commit, state }, params) => { |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
|
|
|
|
|
|
|
|
//commit(ACTIONS.TOGGLE_LOADING);
|
|
|
|
//commit(ACTIONS.TOGGLE_LOADING);
|
|
|
|
|
|
|
|
|
|
|
@ -150,281 +150,281 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
.findAll({ params }) |
|
|
|
.findAll({ params }) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((retrieved) => { |
|
|
|
.then((retrieved) => { |
|
|
|
console.log("result of retrieved"); |
|
|
|
console.log("result of retrieved") |
|
|
|
//commit(ACTIONS.TOGGLE_LOADING);
|
|
|
|
//commit(ACTIONS.TOGGLE_LOADING);
|
|
|
|
|
|
|
|
|
|
|
|
return retrieved["hydra:member"]; |
|
|
|
return retrieved["hydra:member"] |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
fetchAll: ({ commit, state }, params) => { |
|
|
|
fetchAll: ({ commit, state }, params) => { |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
|
|
|
|
|
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.findAll({ params }) |
|
|
|
.findAll({ params }) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((retrieved) => { |
|
|
|
.then((retrieved) => { |
|
|
|
console.log("result of retrieved"); |
|
|
|
console.log("result of retrieved") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.SET_TOTAL_ITEMS, retrieved["hydra:totalItems"]); |
|
|
|
commit(ACTIONS.SET_TOTAL_ITEMS, retrieved["hydra:totalItems"]) |
|
|
|
commit(ACTIONS.SET_VIEW, retrieved["hydra:view"]); |
|
|
|
commit(ACTIONS.SET_VIEW, retrieved["hydra:view"]) |
|
|
|
commit(ACTIONS.SET_RECENTS, retrieved["hydra:member"]); |
|
|
|
commit(ACTIONS.SET_RECENTS, retrieved["hydra:member"]) |
|
|
|
if (true === state.resetList) { |
|
|
|
if (true === state.resetList) { |
|
|
|
commit(ACTIONS.RESET_LIST); |
|
|
|
commit(ACTIONS.RESET_LIST) |
|
|
|
} |
|
|
|
} |
|
|
|
retrieved["hydra:member"].forEach((item) => { |
|
|
|
retrieved["hydra:member"].forEach((item) => { |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)); |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)) |
|
|
|
}); |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
fetchSelectItems: ({ commit }, { params = { properties: ["@id", "name"] } } = {}) => { |
|
|
|
fetchSelectItems: ({ commit }, { params = { properties: ["@id", "name"] } } = {}) => { |
|
|
|
console.log("fetchSelectItems"); |
|
|
|
console.log("fetchSelectItems") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.findAll({ params }) |
|
|
|
.findAll({ params }) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((retrieved) => { |
|
|
|
.then((retrieved) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.SET_SELECT_ITEMS, retrieved["hydra:member"]); |
|
|
|
commit(ACTIONS.SET_SELECT_ITEMS, retrieved["hydra:member"]) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
loadWithQuery: ({ commit }, params = {}) => { |
|
|
|
loadWithQuery: ({ commit }, params = {}) => { |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
|
|
|
|
|
|
|
|
const id = params["id"]; |
|
|
|
const id = params["id"] |
|
|
|
delete params["id"]; |
|
|
|
delete params["id"] |
|
|
|
|
|
|
|
|
|
|
|
if (isEmpty(id)) { |
|
|
|
if (isEmpty(id)) { |
|
|
|
throw new Error("Incorrect id"); |
|
|
|
throw new Error("Incorrect id") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
service |
|
|
|
service |
|
|
|
.find(id, params) |
|
|
|
.find(id, params) |
|
|
|
//.then(response => service.checkResponse(response))
|
|
|
|
//.then(response => service.checkResponse(response))
|
|
|
|
.then((response) => { |
|
|
|
.then((response) => { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((item) => { |
|
|
|
.then((item) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)); |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
load: ({ commit }, id) => { |
|
|
|
load: ({ commit }, id) => { |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
console.log("crud load"); |
|
|
|
console.log("crud load") |
|
|
|
|
|
|
|
|
|
|
|
if (isEmpty(id)) { |
|
|
|
if (isEmpty(id)) { |
|
|
|
throw new Error("Incorrect id"); |
|
|
|
throw new Error("Incorrect id") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
service |
|
|
|
service |
|
|
|
.find(id) |
|
|
|
.find(id) |
|
|
|
//.then(response => service.checkResponse(response))
|
|
|
|
//.then(response => service.checkResponse(response))
|
|
|
|
.then((response) => { |
|
|
|
.then((response) => { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
.then((item) => { |
|
|
|
.then((item) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)); |
|
|
|
commit(ACTIONS.ADD, normalizeRelations(item)) |
|
|
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
return item |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
); |
|
|
|
) |
|
|
|
}, |
|
|
|
}, |
|
|
|
findCourse: ({ commit }, params) => { |
|
|
|
findCourse: ({ commit }, params) => { |
|
|
|
const id = params["id"]; |
|
|
|
const id = params["id"] |
|
|
|
delete params["id"]; |
|
|
|
delete params["id"] |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
console.log("findCourse"); |
|
|
|
console.log("findCourse") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.find(id, params) |
|
|
|
.find(id, params) |
|
|
|
.then((response) => { |
|
|
|
.then((response) => { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.then((item) => { |
|
|
|
.then((item) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD_COURSE, item); |
|
|
|
commit(ACTIONS.ADD_COURSE, item) |
|
|
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
return item |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
cleanSession: ({ commit }) => { |
|
|
|
cleanSession: ({ commit }) => { |
|
|
|
commit(ACTIONS.REMOVE_SESSION); |
|
|
|
commit(ACTIONS.REMOVE_SESSION) |
|
|
|
}, |
|
|
|
}, |
|
|
|
findSession: ({ commit }, params) => { |
|
|
|
findSession: ({ commit }, params) => { |
|
|
|
const id = params["id"]; |
|
|
|
const id = params["id"] |
|
|
|
delete params["id"]; |
|
|
|
delete params["id"] |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.find(id, params) |
|
|
|
.find(id, params) |
|
|
|
.then((response) => { |
|
|
|
.then((response) => { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.then((item) => { |
|
|
|
.then((item) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD_SESSION, item); |
|
|
|
commit(ACTIONS.ADD_SESSION, item) |
|
|
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
return item |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
findResourceNode: ({ commit }, params) => { |
|
|
|
findResourceNode: ({ commit }, params) => { |
|
|
|
const id = params["id"]; |
|
|
|
const id = params["id"] |
|
|
|
delete params["id"]; |
|
|
|
delete params["id"] |
|
|
|
console.log("findResourceNode", id); |
|
|
|
console.log("findResourceNode", id) |
|
|
|
if (!service) throw new Error("No service specified!"); |
|
|
|
if (!service) throw new Error("No service specified!") |
|
|
|
|
|
|
|
|
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.find(id, params) |
|
|
|
.find(id, params) |
|
|
|
.then((response) => { |
|
|
|
.then((response) => { |
|
|
|
if (200 === response.status) { |
|
|
|
if (200 === response.status) { |
|
|
|
return response.json(); |
|
|
|
return response.json() |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
.then((item) => { |
|
|
|
.then((item) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.ADD_RESOURCE_NODE, item); |
|
|
|
commit(ACTIONS.ADD_RESOURCE_NODE, item) |
|
|
|
|
|
|
|
|
|
|
|
return item; |
|
|
|
return item |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
resetCreate: ({ commit }) => { |
|
|
|
resetCreate: ({ commit }) => { |
|
|
|
commit(ACTIONS.RESET_CREATE); |
|
|
|
commit(ACTIONS.RESET_CREATE) |
|
|
|
}, |
|
|
|
}, |
|
|
|
resetDelete: ({ commit }) => { |
|
|
|
resetDelete: ({ commit }) => { |
|
|
|
commit(ACTIONS.RESET_DELETE); |
|
|
|
commit(ACTIONS.RESET_DELETE) |
|
|
|
}, |
|
|
|
}, |
|
|
|
resetShow: ({ commit }) => { |
|
|
|
resetShow: ({ commit }) => { |
|
|
|
commit(ACTIONS.RESET_SHOW); |
|
|
|
commit(ACTIONS.RESET_SHOW) |
|
|
|
}, |
|
|
|
}, |
|
|
|
resetList: ({ commit }) => { |
|
|
|
resetList: ({ commit }) => { |
|
|
|
commit(ACTIONS.RESET_LIST); |
|
|
|
commit(ACTIONS.RESET_LIST) |
|
|
|
}, |
|
|
|
}, |
|
|
|
resetUpdate: ({ commit }) => { |
|
|
|
resetUpdate: ({ commit }) => { |
|
|
|
commit(ACTIONS.RESET_UPDATE); |
|
|
|
commit(ACTIONS.RESET_UPDATE) |
|
|
|
}, |
|
|
|
}, |
|
|
|
update: ({ commit }, item) => { |
|
|
|
update: ({ commit }, item) => { |
|
|
|
console.log("crud update"); |
|
|
|
console.log("crud update") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.update(item) |
|
|
|
.update(item) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((data) => { |
|
|
|
.then((data) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.SET_UPDATED, data); |
|
|
|
commit(ACTIONS.SET_UPDATED, data) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
updateWithFormData: ({ commit }, item) => { |
|
|
|
updateWithFormData: ({ commit }, item) => { |
|
|
|
console.log("crud updateWithFormData"); |
|
|
|
console.log("crud updateWithFormData") |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
|
|
|
|
|
|
|
|
return service |
|
|
|
return service |
|
|
|
.updateWithFormData(item) |
|
|
|
.updateWithFormData(item) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((response) => response.json()) |
|
|
|
.then((data) => { |
|
|
|
.then((data) => { |
|
|
|
commit(ACTIONS.TOGGLE_LOADING); |
|
|
|
commit(ACTIONS.TOGGLE_LOADING) |
|
|
|
commit(ACTIONS.SET_UPDATED, data); |
|
|
|
commit(ACTIONS.SET_UPDATED, data) |
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch((e) => handleError(commit, e)); |
|
|
|
.catch((e) => handleError(commit, e)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
getters: { |
|
|
|
getters: { |
|
|
|
find: (state) => (id) => { |
|
|
|
find: (state) => (id) => { |
|
|
|
return resolveRelations(state.byId[id]); |
|
|
|
return resolveRelations(state.byId[id]) |
|
|
|
}, |
|
|
|
}, |
|
|
|
getField, |
|
|
|
getField, |
|
|
|
list: (state, getters) => { |
|
|
|
list: (state, getters) => { |
|
|
|
return state.allIds.map((id) => getters.find(id)); |
|
|
|
return state.allIds.map((id) => getters.find(id)) |
|
|
|
}, |
|
|
|
}, |
|
|
|
getResourceNode: (state) => { |
|
|
|
getResourceNode: (state) => { |
|
|
|
return state.resourceNode; |
|
|
|
return state.resourceNode |
|
|
|
}, |
|
|
|
}, |
|
|
|
getCourse: (state) => { |
|
|
|
getCourse: (state) => { |
|
|
|
return state.course; |
|
|
|
return state.course |
|
|
|
}, |
|
|
|
}, |
|
|
|
getSession: (state) => { |
|
|
|
getSession: (state) => { |
|
|
|
return state.session; |
|
|
|
return state.session |
|
|
|
}, |
|
|
|
}, |
|
|
|
getDeleted(state) { |
|
|
|
getDeleted(state) { |
|
|
|
return state.deleted; |
|
|
|
return state.deleted |
|
|
|
}, |
|
|
|
}, |
|
|
|
getTotalItems: (state) => { |
|
|
|
getTotalItems: (state) => { |
|
|
|
return state.totalItems; |
|
|
|
return state.totalItems |
|
|
|
}, |
|
|
|
}, |
|
|
|
getRecents: (state) => { |
|
|
|
getRecents: (state) => { |
|
|
|
return state.recents; |
|
|
|
return state.recents |
|
|
|
}, |
|
|
|
}, |
|
|
|
isLoading(state) { |
|
|
|
isLoading(state) { |
|
|
|
return state.isLoading; |
|
|
|
return state.isLoading |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
mutations: { |
|
|
|
mutations: { |
|
|
|
updateField, |
|
|
|
updateField, |
|
|
|
[ACTIONS.ADD_COURSE]: (state, item) => { |
|
|
|
[ACTIONS.ADD_COURSE]: (state, item) => { |
|
|
|
state.course = item; |
|
|
|
state.course = item |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.ADD_SESSION]: (state, item) => { |
|
|
|
[ACTIONS.ADD_SESSION]: (state, item) => { |
|
|
|
state.session = item; |
|
|
|
state.session = item |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.REMOVE_SESSION]: (state) => { |
|
|
|
[ACTIONS.REMOVE_SESSION]: (state) => { |
|
|
|
state.session = null; |
|
|
|
state.session = null |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.ADD_RESOURCE_NODE]: (state, item) => { |
|
|
|
[ACTIONS.ADD_RESOURCE_NODE]: (state, item) => { |
|
|
|
state.resourceNode = item; |
|
|
|
state.resourceNode = item |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'resourceNode', item);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.ADD]: (state, item) => { |
|
|
|
[ACTIONS.ADD]: (state, item) => { |
|
|
|
//this.$set(state.byId, item['@id'], item);
|
|
|
|
//this.$set(state.byId, item['@id'], item);
|
|
|
|
state.byId[item["@id"]] = item; |
|
|
|
state.byId[item["@id"]] = item |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
//this.$set(state, 'isLoading', false);
|
|
|
|
if (state.allIds.includes(item["@id"])) { |
|
|
|
if (state.allIds.includes(item["@id"])) { |
|
|
|
return; |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
state.allIds.push(item["@id"]); |
|
|
|
state.allIds.push(item["@id"]) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_RECENTS]: (state, items) => (state.recents = items), |
|
|
|
[ACTIONS.SET_RECENTS]: (state, items) => (state.recents = items), |
|
|
|
[ACTIONS.RESET_CREATE]: (state) => { |
|
|
|
[ACTIONS.RESET_CREATE]: (state) => { |
|
|
@ -433,14 +433,14 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
error: "", |
|
|
|
error: "", |
|
|
|
created: null, |
|
|
|
created: null, |
|
|
|
violations: null, |
|
|
|
violations: null, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.RESET_DELETE]: (state) => { |
|
|
|
[ACTIONS.RESET_DELETE]: (state) => { |
|
|
|
Object.assign(state, { |
|
|
|
Object.assign(state, { |
|
|
|
isLoading: false, |
|
|
|
isLoading: false, |
|
|
|
error: "", |
|
|
|
error: "", |
|
|
|
deleted: null, |
|
|
|
deleted: null, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.RESET_LIST]: (state) => { |
|
|
|
[ACTIONS.RESET_LIST]: (state) => { |
|
|
|
Object.assign(state, { |
|
|
|
Object.assign(state, { |
|
|
@ -449,13 +449,13 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
error: "", |
|
|
|
error: "", |
|
|
|
isLoading: false, |
|
|
|
isLoading: false, |
|
|
|
resetList: false, |
|
|
|
resetList: false, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.RESET_SHOW]: (state) => { |
|
|
|
[ACTIONS.RESET_SHOW]: (state) => { |
|
|
|
Object.assign(state, { |
|
|
|
Object.assign(state, { |
|
|
|
error: "", |
|
|
|
error: "", |
|
|
|
isLoading: false, |
|
|
|
isLoading: false, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.RESET_UPDATE]: (state) => { |
|
|
|
[ACTIONS.RESET_UPDATE]: (state) => { |
|
|
|
Object.assign(state, { |
|
|
|
Object.assign(state, { |
|
|
@ -463,27 +463,27 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
isLoading: false, |
|
|
|
isLoading: false, |
|
|
|
updated: null, |
|
|
|
updated: null, |
|
|
|
violations: null, |
|
|
|
violations: null, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_CREATED]: (state, created) => { |
|
|
|
[ACTIONS.SET_CREATED]: (state, created) => { |
|
|
|
//console.log('set _created');
|
|
|
|
//console.log('set _created');
|
|
|
|
//console.log(created);
|
|
|
|
//console.log(created);
|
|
|
|
Object.assign(state, { created }); |
|
|
|
Object.assign(state, { created }) |
|
|
|
state.created = created; |
|
|
|
state.created = created |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_DELETED]: (state, deleted) => { |
|
|
|
[ACTIONS.SET_DELETED]: (state, deleted) => { |
|
|
|
//console.log('SET_DELETED');
|
|
|
|
//console.log('SET_DELETED');
|
|
|
|
if (!state.allIds.includes(deleted["@id"])) { |
|
|
|
if (!state.allIds.includes(deleted["@id"])) { |
|
|
|
return; |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
Object.assign(state, { |
|
|
|
Object.assign(state, { |
|
|
|
allIds: remove(state.allIds, (item) => item["@id"] === deleted["@id"]), |
|
|
|
allIds: remove(state.allIds, (item) => item["@id"] === deleted["@id"]), |
|
|
|
byId: remove(state.byId, (id) => id === deleted["@id"]), |
|
|
|
byId: remove(state.byId, (id) => id === deleted["@id"]), |
|
|
|
deleted, |
|
|
|
deleted, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_DELETED_MULTIPLE]: (state, deleted) => { |
|
|
|
[ACTIONS.SET_DELETED_MULTIPLE]: (state, deleted) => { |
|
|
|
console.log("SET_DELETED_MULTIPLE"); |
|
|
|
console.log("SET_DELETED_MULTIPLE") |
|
|
|
//console.log(deleted['@id']);
|
|
|
|
//console.log(deleted['@id']);
|
|
|
|
/*if (!state.allIds.includes(deleted['@id'])) { |
|
|
|
/*if (!state.allIds.includes(deleted['@id'])) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -492,11 +492,11 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
allIds: remove(state.allIds, (item) => item["@id"] === deleted["@id"]), |
|
|
|
allIds: remove(state.allIds, (item) => item["@id"] === deleted["@id"]), |
|
|
|
byId: remove(state.byId, (id) => id === deleted["@id"]), |
|
|
|
byId: remove(state.byId, (id) => id === deleted["@id"]), |
|
|
|
deleted, |
|
|
|
deleted, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_ERROR]: (state, error) => { |
|
|
|
[ACTIONS.SET_ERROR]: (state, error) => { |
|
|
|
state.error = error; |
|
|
|
state.error = error |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
//Object.assign(state, { error, isLoading: false });
|
|
|
|
//Object.assign(state, { error, isLoading: false });
|
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_SELECT_ITEMS]: (state, selectItems) => { |
|
|
|
[ACTIONS.SET_SELECT_ITEMS]: (state, selectItems) => { |
|
|
@ -504,17 +504,17 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
error: "", |
|
|
|
error: "", |
|
|
|
isLoading: false, |
|
|
|
isLoading: false, |
|
|
|
selectItems, |
|
|
|
selectItems, |
|
|
|
}); |
|
|
|
}) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_TOTAL_ITEMS]: (state, totalItems) => { |
|
|
|
[ACTIONS.SET_TOTAL_ITEMS]: (state, totalItems) => { |
|
|
|
Object.assign(state, { totalItems }); |
|
|
|
Object.assign(state, { totalItems }) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_UPDATED]: (state, updated) => { |
|
|
|
[ACTIONS.SET_UPDATED]: (state, updated) => { |
|
|
|
console.log("SET_UPDATED"); |
|
|
|
console.log("SET_UPDATED") |
|
|
|
console.log(updated); |
|
|
|
console.log(updated) |
|
|
|
state.byId[updated["@id"]] = updated; |
|
|
|
state.byId[updated["@id"]] = updated |
|
|
|
state.isLoading = false; |
|
|
|
state.isLoading = false |
|
|
|
state.updated = updated; |
|
|
|
state.updated = updated |
|
|
|
/*Object.assign(state, { |
|
|
|
/*Object.assign(state, { |
|
|
|
byId: { |
|
|
|
byId: { |
|
|
|
[updated['@id']]: updated |
|
|
|
[updated['@id']]: updated |
|
|
@ -523,16 +523,16 @@ export default function makeCrudModule({ normalizeRelations = (x) => x, resolveR |
|
|
|
});*/ |
|
|
|
});*/ |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_VIEW]: (state, view) => { |
|
|
|
[ACTIONS.SET_VIEW]: (state, view) => { |
|
|
|
Object.assign(state, { view }); |
|
|
|
Object.assign(state, { view }) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.SET_VIOLATIONS]: (state, violations) => { |
|
|
|
[ACTIONS.SET_VIOLATIONS]: (state, violations) => { |
|
|
|
Object.assign(state, { violations }); |
|
|
|
Object.assign(state, { violations }) |
|
|
|
}, |
|
|
|
}, |
|
|
|
[ACTIONS.TOGGLE_LOADING]: (state) => { |
|
|
|
[ACTIONS.TOGGLE_LOADING]: (state) => { |
|
|
|
Object.assign(state, { error: "", isLoading: !state.isLoading }); |
|
|
|
Object.assign(state, { error: "", isLoading: !state.isLoading }) |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
namespaced: true, |
|
|
|
namespaced: true, |
|
|
|
state: initialState, |
|
|
|
state: initialState, |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|