Introduce machine type support for Self-Serve module:
- Add `DepartmentSelfServeMachineTypes` routes and components. - Extend condition and rule objects to support machine type attributes. - Update UI flows for managing machine types and conditions. - Adjust creation forms to handle machine type associations. - Implement API changes for machine type retrieval and assignment. - Add utility functions and async data parsing for machine type handling.
This commit is contained in:
@@ -47,18 +47,6 @@ const closeModal = () => {
|
||||
</span>
|
||||
<span>{{ t('modals.add_question_rule') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_condition_rules.showCreateObjectForm({
|
||||
condition_id: condition.id,
|
||||
object_type: 'task',
|
||||
}, loadList)"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-tasks"></i>
|
||||
</span>
|
||||
<span>{{ t('modals.add_task_rule') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_condition_rules.showCreateObjectForm({
|
||||
|
||||
@@ -64,8 +64,6 @@ const props = defineProps({
|
||||
:parse-function="(id) => {
|
||||
if (object.object_type === 'question') {
|
||||
return SessionUser.objects.self_serve_questions.functions.getQuestionText(id);
|
||||
} else if (object.object_type === 'task') {
|
||||
return SessionUser.objects.self_serve_tasks.functions.getTaskText(id);
|
||||
} else if (object.object_type === 'condition') {
|
||||
return SessionUser.objects.self_serve_conditions.functions.getConditionName(id);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export const init = () => {
|
||||
// Check if the window is in /superuser/users/user
|
||||
// Define the default object
|
||||
let defaultObject = {
|
||||
customer_id: 43323914,
|
||||
customer_id: null,
|
||||
reg: null,
|
||||
wash_subscription: false,
|
||||
type: 0,
|
||||
@@ -60,7 +60,7 @@ export const init = () => {
|
||||
};
|
||||
// Skip checks:
|
||||
let includeChecks = {
|
||||
customer_id: false,
|
||||
customer_id: true,
|
||||
reg: true,
|
||||
wash_subscription: false,
|
||||
type: false,
|
||||
|
||||
@@ -47,6 +47,7 @@ import {SelfServeTasks} from "@/components/session/token/SessionUser/Objects/Sel
|
||||
import {SelfServeConditions} from "@/components/session/token/SessionUser/Objects/SelfServeConditions.vue";
|
||||
import {SelfServeVehicleConditions} from "@/components/session/token/SessionUser/Objects/SelfServeVehicleConditions.vue";
|
||||
import {SelfServeConditionRules} from "@/components/session/token/SessionUser/Objects/SelfServeConditionRules.vue";
|
||||
import {SelfServeMachineTypes} from "@/components/session/token/SessionUser/Objects/SelfServeMachineTypes.vue";
|
||||
import {ObjectsGlobal} from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import Swal from "sweetalert2";
|
||||
import router from "@/router.js";
|
||||
@@ -488,6 +489,7 @@ export const SessionUser = {
|
||||
self_serve_conditions: SelfServeConditions,
|
||||
self_serve_vehicle_conditions: SelfServeVehicleConditions,
|
||||
self_serve_condition_rules: SelfServeConditionRules,
|
||||
self_serve_machine_types: SelfServeMachineTypes,
|
||||
subuser_grants: SubuserGrants,
|
||||
global: ObjectsGlobal,
|
||||
},
|
||||
|
||||
@@ -82,10 +82,28 @@ const t = (key) => i18n.global.t(key);
|
||||
creation: {
|
||||
required: false
|
||||
}
|
||||
},
|
||||
machine_type_id: {
|
||||
label: 'Self-serve maskintype',
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: false
|
||||
},
|
||||
options: async () => {
|
||||
const machineTypes = await SessionUser.objects.self_serve_machine_types.get.all();
|
||||
return [
|
||||
{ id: 0, name: t('global.none') },
|
||||
...machineTypes.map((entry) => ({
|
||||
id: entry.id,
|
||||
name: entry.name,
|
||||
}))
|
||||
];
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
add: async (department, name, relay_in_id = null, relay_out_id = null, relay_machine_id = null, dynamic_image_id = null) => {
|
||||
add: async (department, name, relay_in_id = null, relay_out_id = null, relay_machine_id = null, dynamic_image_id = null, machine_type_id = null) => {
|
||||
return ObjectsGlobal.add.object(
|
||||
DepartmentLanes.meta.endpoint,
|
||||
{
|
||||
@@ -94,7 +112,8 @@ const t = (key) => i18n.global.t(key);
|
||||
relay_in_id: relay_in_id,
|
||||
relay_out_id: relay_out_id,
|
||||
relay_machine_id: relay_machine_id,
|
||||
dynamic_image_id: dynamic_image_id ? parseInt(dynamic_image_id) : null
|
||||
dynamic_image_id: dynamic_image_id ? parseInt(dynamic_image_id) : null,
|
||||
machine_type_id: machine_type_id ? parseInt(machine_type_id) : null
|
||||
}
|
||||
);
|
||||
},
|
||||
@@ -147,6 +166,14 @@ const t = (key) => i18n.global.t(key);
|
||||
dynamic_image_id ? parseInt(dynamic_image_id) : null
|
||||
)
|
||||
},
|
||||
machine_type_id: async (id, machine_type_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
DepartmentLanes.meta.endpoint,
|
||||
id,
|
||||
"machine_type_id",
|
||||
machine_type_id && parseInt(machine_type_id) !== 0 ? parseInt(machine_type_id) : null
|
||||
)
|
||||
},
|
||||
},
|
||||
get: {
|
||||
all: async () => {
|
||||
@@ -253,4 +280,4 @@ const t = (key) => i18n.global.t(key);
|
||||
);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
import {ref} from "vue";
|
||||
import { ref } from "vue";
|
||||
|
||||
/**
|
||||
* Local condition rules cache
|
||||
@@ -24,7 +24,16 @@ export const getConditionRuleName = (id, fallback = null) => {
|
||||
}
|
||||
const rule = condition_rules_cache.value.find((rule) => rule.id === parseInt(id));
|
||||
return rule ? rule.name : fallback === null ? SessionUser.objects.global.language.no_data : fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const normalizePayload = (payload) => ({
|
||||
condition_id: parseInt(payload.condition_id),
|
||||
type: payload.type,
|
||||
object_type: payload.object_type,
|
||||
object_id: parseInt(payload.object_id),
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
});
|
||||
|
||||
/**
|
||||
* The SelfServeConditionRules object
|
||||
@@ -60,27 +69,23 @@ export const SelfServeConditionRules = {
|
||||
let conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const departmentId = lockedValues.department || lockedValues.department_id;
|
||||
const productId = lockedValues.product || lockedValues.vehicle_type || lockedValues.product_id;
|
||||
const machineTypeId = lockedValues.machine_type_id;
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department) === parseInt(departmentId));
|
||||
}
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product) === parseInt(productId));
|
||||
if (machineTypeId) {
|
||||
conditions = conditions.filter(c => parseInt(c.machine_type_id || 0) === parseInt(machineTypeId));
|
||||
} else {
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department || 0) === parseInt(departmentId));
|
||||
}
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product || 0) === parseInt(productId));
|
||||
}
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
return conditions.map((c) => {
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(c.department))?.name || c.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(c.product))?.name || c.product;
|
||||
return {
|
||||
...c,
|
||||
name: `${departmentName}-${c.lane}-${productName}: ${c.name}`
|
||||
};
|
||||
});
|
||||
return Promise.all(conditions.map(async (condition) => ({
|
||||
...condition,
|
||||
name: await SessionUser.objects.self_serve_conditions.functions.formatConditionName(condition.id)
|
||||
})));
|
||||
},
|
||||
parse: (id) => {
|
||||
return SessionUser.objects.self_serve_conditions.functions.getConditionName(id);
|
||||
@@ -100,9 +105,7 @@ export const SelfServeConditionRules = {
|
||||
{ id: "IS_TRUE_OR_NOT_SET", name: "Er sand eller ikke sat" },
|
||||
{ id: "IS_FALSE_OR_NOT_SET", name: "Er falsk eller ikke sat" },
|
||||
{ id: "IS_SET", name: "Er sat" },
|
||||
{ id: "IS_NOT_SET", name: "Er ikke sat" },
|
||||
{ id: "IS_TRUE_OR_ANY_TRUE", name: "Er sand, eller betingelsen indeholder mindst én sand regel" },
|
||||
{ id: "IS_FALSE_OR_ANY_FALSE", name: "Er falsk, eller betingelsen indeholder mindst én falsk regel" },
|
||||
];
|
||||
}
|
||||
},
|
||||
@@ -116,7 +119,6 @@ export const SelfServeConditionRules = {
|
||||
options: async () => {
|
||||
return [
|
||||
{ id: "question", name: "Spørgsmål" },
|
||||
{ id: "task", name: "Opgave" },
|
||||
{ id: "condition", name: "Betingelse" },
|
||||
];
|
||||
}
|
||||
@@ -129,69 +131,43 @@ export const SelfServeConditionRules = {
|
||||
required: true,
|
||||
onchange: async (event, { setFieldValue, getFieldValue }) => {
|
||||
const objectId = parseInt(event.target.value);
|
||||
const objectType = getFieldValue('object_type');
|
||||
const objectType = getFieldValue("object_type");
|
||||
|
||||
if (objectType === 'question') {
|
||||
if (objectType === "question") {
|
||||
const formattedName = await SessionUser.objects.self_serve_questions.functions.formatQuestionName(objectId);
|
||||
const questions = await SessionUser.objects.self_serve_questions.get.all();
|
||||
const question = questions.find(q => q.id === objectId);
|
||||
const question = questions.find(q => parseInt(q.id) === parseInt(objectId));
|
||||
if (question) {
|
||||
setFieldValue('name', formattedName);
|
||||
setFieldValue('description', question.description || '');
|
||||
setFieldValue("name", formattedName);
|
||||
setFieldValue("description", question.description || "");
|
||||
}
|
||||
} else if (objectType === 'task') {
|
||||
const formattedName = await SessionUser.objects.self_serve_tasks.functions.formatTaskName(objectId);
|
||||
const tasks = await SessionUser.objects.self_serve_tasks.get.all();
|
||||
const task = tasks.find(t => t.id === objectId);
|
||||
if (task) {
|
||||
setFieldValue('name', formattedName);
|
||||
setFieldValue('description', task.description || '');
|
||||
}
|
||||
} else if (objectType === 'condition') {
|
||||
} else if (objectType === "condition") {
|
||||
const formattedName = await SessionUser.objects.self_serve_conditions.functions.formatConditionName(objectId);
|
||||
const conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const condition = conditions.find(c => c.id === objectId);
|
||||
const condition = conditions.find(c => parseInt(c.id) === parseInt(objectId));
|
||||
if (condition) {
|
||||
setFieldValue('name', formattedName);
|
||||
setFieldValue('description', condition.description || '');
|
||||
setFieldValue("name", formattedName);
|
||||
setFieldValue("description", condition.description || "");
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
const objectType = lockedValues.object_type;
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const formatName = (obj, nameKey) => {
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(obj.department))?.name || obj.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(obj.product))?.name || obj.product;
|
||||
return `${departmentName}-${obj.lane}-${productName}: ${obj[nameKey]}`;
|
||||
};
|
||||
|
||||
if (objectType === 'question') {
|
||||
if (objectType === "question") {
|
||||
const questions = await SessionUser.objects.self_serve_questions.get.all();
|
||||
return questions.map(q => ({ id: q.id, name: formatName(q, 'question') }));
|
||||
} else if (objectType === 'task') {
|
||||
const tasks = await SessionUser.objects.self_serve_tasks.get.all();
|
||||
return tasks.map(t => ({ id: t.id, name: formatName(t, 'task') }));
|
||||
} else if (objectType === 'condition') {
|
||||
const conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
return conditions.map(c => ({ id: c.id, name: formatName(c, 'name') }));
|
||||
} else {
|
||||
const [questions, tasks, conditions] = await Promise.all([
|
||||
SessionUser.objects.self_serve_questions.get.all(),
|
||||
SessionUser.objects.self_serve_tasks.get.all(),
|
||||
SessionUser.objects.self_serve_conditions.get.all()
|
||||
]);
|
||||
return [
|
||||
...questions.map(q => ({ id: q.id, name: `[Spørgsmål] ${formatName(q, 'question')}` })),
|
||||
...tasks.map(t => ({ id: t.id, name: `[Opgave] ${formatName(t, 'task')}` })),
|
||||
...conditions.map(c => ({ id: c.id, name: `[Betingelse] ${formatName(c, 'name')}` }))
|
||||
];
|
||||
return Promise.all(questions.map(async (question) => ({
|
||||
id: question.id,
|
||||
name: await SessionUser.objects.self_serve_questions.functions.formatQuestionName(question.id)
|
||||
})));
|
||||
}
|
||||
|
||||
const conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
return Promise.all(conditions.map(async (condition) => ({
|
||||
id: condition.id,
|
||||
name: await SessionUser.objects.self_serve_conditions.functions.formatConditionName(condition.id)
|
||||
})));
|
||||
}
|
||||
},
|
||||
name: {
|
||||
@@ -211,67 +187,38 @@ export const SelfServeConditionRules = {
|
||||
}
|
||||
},
|
||||
},
|
||||
add: async (condition_id, type, object_type, object_id, name, description) => {
|
||||
return ObjectsGlobal.add.object(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
{
|
||||
condition_id: parseInt(condition_id),
|
||||
type: type,
|
||||
object_type: object_type,
|
||||
object_id: parseInt(object_id),
|
||||
name: name,
|
||||
description: description,
|
||||
}
|
||||
);
|
||||
add: async (conditionIdOrPayload, type, object_type, object_id, name, description) => {
|
||||
const payload = typeof conditionIdOrPayload === "object"
|
||||
? normalizePayload(conditionIdOrPayload)
|
||||
: normalizePayload({
|
||||
condition_id: conditionIdOrPayload,
|
||||
type,
|
||||
object_type,
|
||||
object_id,
|
||||
name,
|
||||
description,
|
||||
});
|
||||
|
||||
return ObjectsGlobal.add.object(SelfServeConditionRules.meta.endpoint, payload);
|
||||
},
|
||||
set: {
|
||||
condition_id: async (id, condition_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"condition_id",
|
||||
parseInt(condition_id)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "condition_id", parseInt(condition_id));
|
||||
},
|
||||
type: async (id, type) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"type",
|
||||
type
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "type", type);
|
||||
},
|
||||
object_type: async (id, object_type) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"object_type",
|
||||
object_type
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "object_type", object_type);
|
||||
},
|
||||
object_id: async (id, object_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"object_id",
|
||||
parseInt(object_id)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "object_id", parseInt(object_id));
|
||||
},
|
||||
name: async (id, name) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"name",
|
||||
name
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "name", name);
|
||||
},
|
||||
description: async (id, description) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditionRules.meta.endpoint,
|
||||
id,
|
||||
"description",
|
||||
description
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditionRules.meta.endpoint, id, "description", description);
|
||||
},
|
||||
},
|
||||
get: {
|
||||
@@ -294,14 +241,15 @@ export const SelfServeConditionRules = {
|
||||
showCreateObjectForm: (initialData = {}, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showCreateObjectForm(SelfServeConditionRules, onAfterSubmit, initialData);
|
||||
},
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = {}) => {
|
||||
return ObjectsGlobal.showEditObjectFieldForm(
|
||||
SelfServeConditionRules,
|
||||
id,
|
||||
column,
|
||||
value,
|
||||
onAfterSubmit
|
||||
onAfterSubmit,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script>
|
||||
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
import {ref} from "vue";
|
||||
import { ref } from "vue";
|
||||
import { showSelfServeConditionForm } from "@/components/session/token/SessionUser/Objects/selfServeObjectForms.js";
|
||||
|
||||
/**
|
||||
* Local conditions cache
|
||||
@@ -24,7 +25,38 @@ export const getConditionName = (id, fallback = null) => {
|
||||
}
|
||||
const condition = conditions_cache.value.find((condition) => condition.id === parseInt(id));
|
||||
return condition ? condition.name : fallback === null ? SessionUser.objects.global.language.no_data : fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const buildScopedConditionName = async (condition) => {
|
||||
if (!condition) {
|
||||
return SessionUser.objects.global.language.no_data;
|
||||
}
|
||||
|
||||
if (condition.machine_type_id) {
|
||||
const machineTypeName = await SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(condition.machine_type_id);
|
||||
return `[Maskintype] ${machineTypeName}: ${condition.name}`;
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(condition.department))?.name || condition.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(condition.product))?.name || condition.product;
|
||||
|
||||
return `${departmentName}-${condition.lane}-${productName}: ${condition.name}`;
|
||||
};
|
||||
|
||||
const normalizePayload = (payload) => ({
|
||||
department: parseInt(payload.department || 0),
|
||||
lane: parseInt(payload.lane || 0),
|
||||
product: parseInt(payload.product || 0),
|
||||
machine_type_id: payload.machine_type_id && parseInt(payload.machine_type_id) !== 0 ? parseInt(payload.machine_type_id) : null,
|
||||
condition_id: payload.condition_id && parseInt(payload.condition_id) !== 0 ? parseInt(payload.condition_id) : null,
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
});
|
||||
|
||||
/**
|
||||
* The SelfServeConditions object
|
||||
@@ -54,7 +86,7 @@ export const SelfServeConditions = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
lane: {
|
||||
@@ -62,7 +94,7 @@ export const SelfServeConditions = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
product: {
|
||||
@@ -70,7 +102,7 @@ export const SelfServeConditions = {
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
const products = await SessionUser.objects.products.get.all();
|
||||
@@ -80,6 +112,30 @@ export const SelfServeConditions = {
|
||||
return products;
|
||||
}
|
||||
},
|
||||
machine_type_id: {
|
||||
label: "Maskintype",
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: false
|
||||
},
|
||||
options: async () => {
|
||||
const machineTypes = await SessionUser.objects.self_serve_machine_types.get.all();
|
||||
return [
|
||||
{ id: 0, name: "Ingen" },
|
||||
...machineTypes.map((entry) => ({
|
||||
id: entry.id,
|
||||
name: entry.name,
|
||||
}))
|
||||
];
|
||||
},
|
||||
parse: (id) => {
|
||||
if (!id) {
|
||||
return "Ingen";
|
||||
}
|
||||
return SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(id);
|
||||
}
|
||||
},
|
||||
condition_id: {
|
||||
label: "Betingelse (Hvis)",
|
||||
type: "select",
|
||||
@@ -91,28 +147,26 @@ export const SelfServeConditions = {
|
||||
let conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const departmentId = lockedValues.department || lockedValues.department_id;
|
||||
const productId = lockedValues.product || lockedValues.vehicle_type || lockedValues.product_id;
|
||||
const machineTypeId = lockedValues.machine_type_id;
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department) === parseInt(departmentId));
|
||||
if (machineTypeId) {
|
||||
conditions = conditions.filter(c => parseInt(c.machine_type_id || 0) === parseInt(machineTypeId));
|
||||
} else {
|
||||
conditions = conditions.filter(c => !c.machine_type_id);
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department || 0) === parseInt(departmentId));
|
||||
}
|
||||
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product || 0) === parseInt(productId));
|
||||
}
|
||||
}
|
||||
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product) === parseInt(productId));
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const options = conditions.map((c) => {
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(c.department))?.name || c.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(c.product))?.name || c.product;
|
||||
return {
|
||||
...c,
|
||||
name: `${departmentName}-${c.lane}-${productName}: ${c.name}`
|
||||
};
|
||||
});
|
||||
const options = await Promise.all(conditions.map(async (condition) => ({
|
||||
...condition,
|
||||
name: await buildScopedConditionName(condition),
|
||||
})));
|
||||
|
||||
options.unshift({
|
||||
id: 0,
|
||||
@@ -142,67 +196,52 @@ export const SelfServeConditions = {
|
||||
}
|
||||
},
|
||||
},
|
||||
add: async (department, lane, product, name, description, condition_id = null) => {
|
||||
return ObjectsGlobal.add.object(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
{
|
||||
department: parseInt(department),
|
||||
lane: parseInt(lane),
|
||||
product: parseInt(product),
|
||||
name: name,
|
||||
description: description,
|
||||
condition_id: (condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null,
|
||||
}
|
||||
);
|
||||
add: async (departmentOrPayload, lane, product, name, description, condition_id = null, machine_type_id = null) => {
|
||||
const payload = typeof departmentOrPayload === "object"
|
||||
? normalizePayload(departmentOrPayload)
|
||||
: normalizePayload({
|
||||
department: departmentOrPayload,
|
||||
lane,
|
||||
product,
|
||||
name,
|
||||
description,
|
||||
condition_id,
|
||||
machine_type_id,
|
||||
});
|
||||
|
||||
return ObjectsGlobal.add.object(SelfServeConditions.meta.endpoint, payload);
|
||||
},
|
||||
set: {
|
||||
machine_type_id: async (id, machine_type_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"machine_type_id",
|
||||
(machine_type_id && parseInt(machine_type_id) !== 0) ? parseInt(machine_type_id) : null
|
||||
);
|
||||
},
|
||||
condition_id: async (id, condition_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"condition_id",
|
||||
(condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null
|
||||
)
|
||||
);
|
||||
},
|
||||
name: async (id, name) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"name",
|
||||
name
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditions.meta.endpoint, id, "name", name);
|
||||
},
|
||||
description: async (id, description) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"description",
|
||||
description
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditions.meta.endpoint, id, "description", description);
|
||||
},
|
||||
product: async (id, product) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"product",
|
||||
parseInt(product)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditions.meta.endpoint, id, "product", parseInt(product || 0));
|
||||
},
|
||||
lane: async (id, lane) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"lane",
|
||||
parseInt(lane)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditions.meta.endpoint, id, "lane", parseInt(lane || 0));
|
||||
},
|
||||
department: async (id, department) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeConditions.meta.endpoint,
|
||||
id,
|
||||
"department",
|
||||
parseInt(department)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeConditions.meta.endpoint, id, "department", parseInt(department || 0));
|
||||
},
|
||||
},
|
||||
get: {
|
||||
@@ -219,34 +258,55 @@ export const SelfServeConditions = {
|
||||
functions: {
|
||||
getConditionName: getConditionName,
|
||||
formatConditionName: async (conditionId) => {
|
||||
const [conditions, departments, products] = await Promise.all([
|
||||
SessionUser.objects.self_serve_conditions.get.all(),
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
const conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const condition = conditions.find(c => parseInt(c.id) === parseInt(conditionId));
|
||||
if (!condition) return SessionUser.objects.global.language.no_data;
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(condition.department))?.name || condition.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(condition.product))?.name || condition.product;
|
||||
return buildScopedConditionName(condition);
|
||||
},
|
||||
getScopeLabel: async (condition) => {
|
||||
if (condition.machine_type_id) {
|
||||
const machineTypeName = await SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(condition.machine_type_id);
|
||||
return `Maskintype: ${machineTypeName}`;
|
||||
}
|
||||
|
||||
return `${departmentName}-${condition.lane}-${productName}: ${condition.name}`;
|
||||
if (
|
||||
parseInt(condition.department || 0) === 0
|
||||
&& parseInt(condition.lane || 0) === 0
|
||||
&& parseInt(condition.product || 0) === 0
|
||||
) {
|
||||
return "Fælles";
|
||||
}
|
||||
|
||||
return `Afdeling ${condition.department || 0} / Bane ${condition.lane || 0} / Køretøjstype ${condition.product || 0}`;
|
||||
},
|
||||
showDeleteObjectForm: (id, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showDeleteObjectForm(SelfServeConditions, id, onAfterSubmit);
|
||||
},
|
||||
},
|
||||
showCreateObjectForm: (initialData = {}, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showCreateObjectForm(SelfServeConditions, onAfterSubmit, initialData);
|
||||
return showSelfServeConditionForm({
|
||||
object: SelfServeConditions,
|
||||
initialData,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
|
||||
showEditObjectForm: (record, onAfterSubmit = null) => {
|
||||
return showSelfServeConditionForm({
|
||||
object: SelfServeConditions,
|
||||
record,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = {}) => {
|
||||
return ObjectsGlobal.showEditObjectFieldForm(
|
||||
SelfServeConditions,
|
||||
id,
|
||||
column,
|
||||
value,
|
||||
onAfterSubmit
|
||||
onAfterSubmit,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<script>
|
||||
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
import {ref} from "vue";
|
||||
import { ref } from "vue";
|
||||
import { showSelfServeQuestionForm } from "@/components/session/token/SessionUser/Objects/selfServeObjectForms.js";
|
||||
|
||||
/**
|
||||
* Local questions cache
|
||||
@@ -24,7 +25,29 @@ export const getQuestionText = (id, fallback = null) => {
|
||||
}
|
||||
const question = questions_cache.value.find((question) => question.id === parseInt(id));
|
||||
return question ? question.question : fallback === null ? SessionUser.objects.global.language.no_data : fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const normalizePayload = (payload) => ({
|
||||
department: parseInt(payload.department || 0),
|
||||
lane: parseInt(payload.lane || 0),
|
||||
product: parseInt(payload.product || 0),
|
||||
question: payload.question,
|
||||
description: payload.description,
|
||||
condition_id: payload.condition_id && parseInt(payload.condition_id) !== 0 ? parseInt(payload.condition_id) : null,
|
||||
order_priority: parseInt(payload.order_priority || 0),
|
||||
});
|
||||
|
||||
const buildScopedQuestionName = async (question) => {
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(question.department))?.name || question.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(question.product))?.name || question.product;
|
||||
|
||||
return `${departmentName}-${question.lane}-${productName}: ${question.question}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* The SelfServeQuestions object
|
||||
@@ -54,7 +77,7 @@ export const SelfServeQuestions = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
lane: {
|
||||
@@ -62,7 +85,7 @@ export const SelfServeQuestions = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
product: {
|
||||
@@ -70,7 +93,7 @@ export const SelfServeQuestions = {
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
const products = await SessionUser.objects.products.get.all();
|
||||
@@ -101,34 +124,27 @@ export const SelfServeQuestions = {
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
let conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const departmentId = lockedValues.department || lockedValues.department_id;
|
||||
const productId = lockedValues.product || lockedValues.vehicle_type || lockedValues.product_id;
|
||||
|
||||
conditions = conditions.filter(c => !c.machine_type_id);
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department) === parseInt(departmentId));
|
||||
conditions = conditions.filter(c => parseInt(c.department || 0) === parseInt(departmentId));
|
||||
}
|
||||
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product) === parseInt(productId));
|
||||
conditions = conditions.filter(c => parseInt(c.product || 0) === parseInt(productId));
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const options = conditions.map((c) => {
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(c.department))?.name || c.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(c.product))?.name || c.product;
|
||||
return {
|
||||
...c,
|
||||
name: `${departmentName}-${c.lane}-${productName}: ${c.name}`
|
||||
};
|
||||
});
|
||||
const options = await Promise.all(conditions.map(async (condition) => ({
|
||||
...condition,
|
||||
name: await SessionUser.objects.self_serve_conditions.functions.formatConditionName(condition.id)
|
||||
})));
|
||||
|
||||
options.unshift({
|
||||
id: 0,
|
||||
@@ -150,44 +166,30 @@ export const SelfServeQuestions = {
|
||||
}
|
||||
},
|
||||
},
|
||||
add: async (department, lane, product, question, description, condition_id, order_priority) => {
|
||||
return ObjectsGlobal.add.object(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
{
|
||||
department: parseInt(department),
|
||||
lane: parseInt(lane),
|
||||
product: parseInt(product),
|
||||
question: question,
|
||||
description: description,
|
||||
condition_id: (condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null,
|
||||
order_priority: parseInt(order_priority),
|
||||
}
|
||||
);
|
||||
add: async (departmentOrPayload, lane, product, question, description, condition_id, order_priority) => {
|
||||
const payload = typeof departmentOrPayload === "object"
|
||||
? normalizePayload(departmentOrPayload)
|
||||
: normalizePayload({
|
||||
department: departmentOrPayload,
|
||||
lane,
|
||||
product,
|
||||
question,
|
||||
description,
|
||||
condition_id,
|
||||
order_priority,
|
||||
});
|
||||
|
||||
return ObjectsGlobal.add.object(SelfServeQuestions.meta.endpoint, payload);
|
||||
},
|
||||
set: {
|
||||
question: async (id, question) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"question",
|
||||
question
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "question", question);
|
||||
},
|
||||
description: async (id, description) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"description",
|
||||
description
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "description", description);
|
||||
},
|
||||
order_priority: async (id, order_priority) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"order_priority",
|
||||
parseInt(order_priority)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "order_priority", parseInt(order_priority || 0));
|
||||
},
|
||||
condition_id: async (id, condition_id) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
@@ -195,31 +197,16 @@ export const SelfServeQuestions = {
|
||||
id,
|
||||
"condition_id",
|
||||
(condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null
|
||||
)
|
||||
);
|
||||
},
|
||||
product: async (id, product) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"product",
|
||||
parseInt(product)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "product", parseInt(product || 0));
|
||||
},
|
||||
lane: async (id, lane) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"lane",
|
||||
parseInt(lane)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "lane", parseInt(lane || 0));
|
||||
},
|
||||
department: async (id, department) => {
|
||||
return ObjectsGlobal.set.column(
|
||||
SelfServeQuestions.meta.endpoint,
|
||||
id,
|
||||
"department",
|
||||
parseInt(department)
|
||||
)
|
||||
return ObjectsGlobal.set.column(SelfServeQuestions.meta.endpoint, id, "department", parseInt(department || 0));
|
||||
},
|
||||
},
|
||||
get: {
|
||||
@@ -236,47 +223,49 @@ export const SelfServeQuestions = {
|
||||
functions: {
|
||||
getQuestionText: getQuestionText,
|
||||
formatQuestionName: async (questionId) => {
|
||||
const [questions, departments, products] = await Promise.all([
|
||||
SessionUser.objects.self_serve_questions.get.all(),
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
const questions = await SessionUser.objects.self_serve_questions.get.all();
|
||||
const question = questions.find(q => parseInt(q.id) === parseInt(questionId));
|
||||
if (!question) return SessionUser.objects.global.language.no_data;
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(question.department))?.name || question.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(question.product))?.name || question.product;
|
||||
return buildScopedQuestionName(question);
|
||||
},
|
||||
getScopeLabel: async (question) => {
|
||||
if (
|
||||
parseInt(question.department || 0) === 0
|
||||
&& parseInt(question.lane || 0) === 0
|
||||
&& parseInt(question.product || 0) === 0
|
||||
) {
|
||||
return "Fælles";
|
||||
}
|
||||
|
||||
return `${departmentName}-${question.lane}-${productName}: ${question.question}`;
|
||||
return `Afdeling ${question.department || 0} / Bane ${question.lane || 0} / Køretøjstype ${question.product || 0}`;
|
||||
},
|
||||
showDeleteObjectForm: (id, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showDeleteObjectForm(SelfServeQuestions, id, onAfterSubmit);
|
||||
},
|
||||
},
|
||||
/**
|
||||
* Show the create object form
|
||||
* @param initialData
|
||||
* @param onAfterSubmit
|
||||
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
||||
*/
|
||||
showCreateObjectForm: (initialData = {}, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showCreateObjectForm(SelfServeQuestions, onAfterSubmit, initialData);
|
||||
return showSelfServeQuestionForm({
|
||||
object: SelfServeQuestions,
|
||||
initialData,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Show the edit object field form
|
||||
* @param id
|
||||
* @param column
|
||||
* @param value
|
||||
* @param onAfterSubmit
|
||||
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
||||
*/
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null) => {
|
||||
showEditObjectForm: (record, onAfterSubmit = null) => {
|
||||
return showSelfServeQuestionForm({
|
||||
object: SelfServeQuestions,
|
||||
record,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = {}) => {
|
||||
return ObjectsGlobal.showEditObjectFieldForm(
|
||||
SelfServeQuestions,
|
||||
id,
|
||||
column,
|
||||
value,
|
||||
onAfterSubmit
|
||||
onAfterSubmit,
|
||||
options
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script>
|
||||
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
|
||||
import {ref} from "vue";
|
||||
import { authenticatedRequest } from "@/components/session/authenticatedRequest.vue";
|
||||
import { ref } from "vue";
|
||||
import { showSelfServeTaskForm } from "@/components/session/token/SessionUser/Objects/selfServeObjectForms.js";
|
||||
|
||||
/**
|
||||
* Local tasks cache
|
||||
@@ -25,7 +26,42 @@ export const getTaskText = (id, fallback = null) => {
|
||||
}
|
||||
const task = tasks_cache.value.find((task) => task.id === parseInt(id));
|
||||
return task ? task.task : fallback === null ? SessionUser.objects.global.language.no_data : fallback;
|
||||
}
|
||||
};
|
||||
|
||||
const buildScopedTaskName = async (task) => {
|
||||
if (!task) {
|
||||
return SessionUser.objects.global.language.no_data;
|
||||
}
|
||||
|
||||
if (task.machine_type_id) {
|
||||
const machineTypeName = await SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(task.machine_type_id);
|
||||
return `[Maskintype] ${machineTypeName}: ${task.task}`;
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(task.department))?.name || task.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(task.product))?.name || task.product;
|
||||
|
||||
return `${departmentName}-${task.lane}-${productName}: ${task.task}`;
|
||||
};
|
||||
|
||||
const normalizePayload = (payload) => ({
|
||||
department: parseInt(payload.department || 0),
|
||||
lane: parseInt(payload.lane || 0),
|
||||
product: parseInt(payload.product || 0),
|
||||
machine_type_id: payload.machine_type_id && parseInt(payload.machine_type_id) !== 0 ? parseInt(payload.machine_type_id) : null,
|
||||
condition_id: payload.condition_id && parseInt(payload.condition_id) !== 0 ? parseInt(payload.condition_id) : null,
|
||||
task: payload.task,
|
||||
description: payload.description,
|
||||
order_priority: parseInt(payload.order_priority || 0),
|
||||
services: Array.isArray(payload.services) ? payload.services : [],
|
||||
buttons: Array.isArray(payload.buttons) ? payload.buttons.map((button) => parseInt(button)) : [],
|
||||
dynamic_images_vehicle_type: payload.dynamic_images_vehicle_type ? parseInt(payload.dynamic_images_vehicle_type) : null,
|
||||
});
|
||||
|
||||
/**
|
||||
* The SelfServeTasks object
|
||||
@@ -55,7 +91,7 @@ export const SelfServeTasks = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
lane: {
|
||||
@@ -63,7 +99,7 @@ export const SelfServeTasks = {
|
||||
type: "number",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
}
|
||||
},
|
||||
product: {
|
||||
@@ -71,7 +107,7 @@ export const SelfServeTasks = {
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
const products = await SessionUser.objects.products.get.all();
|
||||
@@ -81,38 +117,60 @@ export const SelfServeTasks = {
|
||||
return products;
|
||||
}
|
||||
},
|
||||
machine_type_id: {
|
||||
label: "Maskintype",
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: false
|
||||
},
|
||||
options: async () => {
|
||||
const machineTypes = await SessionUser.objects.self_serve_machine_types.get.all();
|
||||
return [
|
||||
{ id: 0, name: "Ingen" },
|
||||
...machineTypes.map((entry) => ({
|
||||
id: entry.id,
|
||||
name: entry.name,
|
||||
}))
|
||||
];
|
||||
},
|
||||
parse: (id) => {
|
||||
if (!id) {
|
||||
return "Ingen";
|
||||
}
|
||||
return SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(id);
|
||||
}
|
||||
},
|
||||
condition_id: {
|
||||
label: "Hvis",
|
||||
type: "select",
|
||||
sortable: true,
|
||||
creation: {
|
||||
required: true
|
||||
required: false
|
||||
},
|
||||
options: async (lockedValues = {}) => {
|
||||
let conditions = await SessionUser.objects.self_serve_conditions.get.all();
|
||||
const departmentId = lockedValues.department || lockedValues.department_id;
|
||||
const productId = lockedValues.product || lockedValues.vehicle_type || lockedValues.product_id;
|
||||
const machineTypeId = lockedValues.machine_type_id;
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department) === parseInt(departmentId));
|
||||
}
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product) === parseInt(productId));
|
||||
if (machineTypeId) {
|
||||
conditions = conditions.filter(c => parseInt(c.machine_type_id || 0) === parseInt(machineTypeId));
|
||||
} else {
|
||||
conditions = conditions.filter(c => !c.machine_type_id);
|
||||
|
||||
if (departmentId) {
|
||||
conditions = conditions.filter(c => parseInt(c.department || 0) === parseInt(departmentId));
|
||||
}
|
||||
if (productId) {
|
||||
conditions = conditions.filter(c => parseInt(c.product || 0) === parseInt(productId));
|
||||
}
|
||||
}
|
||||
|
||||
const [departments, products] = await Promise.all([
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
|
||||
const options = conditions.map((c) => {
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(c.department))?.name || c.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(c.product))?.name || c.product;
|
||||
return {
|
||||
...c,
|
||||
name: `${departmentName}-${c.lane}-${productName}: ${c.name}`
|
||||
};
|
||||
});
|
||||
const options = await Promise.all(conditions.map(async (condition) => ({
|
||||
...condition,
|
||||
name: await SessionUser.objects.self_serve_conditions.functions.formatConditionName(condition.id)
|
||||
})));
|
||||
|
||||
options.unshift({
|
||||
id: 0,
|
||||
@@ -157,7 +215,6 @@ export const SelfServeTasks = {
|
||||
required: false
|
||||
},
|
||||
options: async () => {
|
||||
// Return available service options based on SelfserveLaneService enum
|
||||
return [
|
||||
{ id: "MACHINE", name: "MACHINE" }
|
||||
];
|
||||
@@ -202,28 +259,30 @@ export const SelfServeTasks = {
|
||||
}
|
||||
},
|
||||
},
|
||||
add: async (department, lane, product, condition_id, task, description, order_priority) => {
|
||||
return ObjectsGlobal.add.object(
|
||||
SelfServeTasks.meta.endpoint,
|
||||
{
|
||||
department: parseInt(department),
|
||||
lane: parseInt(lane),
|
||||
product: parseInt(product),
|
||||
condition_id: (condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null,
|
||||
task: task,
|
||||
description: description,
|
||||
order_priority: parseInt(order_priority),
|
||||
}
|
||||
);
|
||||
add: async (departmentOrPayload, lane, product, condition_id, task, description, order_priority) => {
|
||||
const payload = typeof departmentOrPayload === "object"
|
||||
? normalizePayload(departmentOrPayload)
|
||||
: normalizePayload({
|
||||
department: departmentOrPayload,
|
||||
lane,
|
||||
product,
|
||||
condition_id,
|
||||
task,
|
||||
description,
|
||||
order_priority,
|
||||
});
|
||||
|
||||
return ObjectsGlobal.add.object(SelfServeTasks.meta.endpoint, payload);
|
||||
},
|
||||
set: {
|
||||
task: (id, task) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "task", task),
|
||||
description: (id, description) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "description", description),
|
||||
order_priority: (id, order_priority) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "order_priority", parseInt(order_priority)),
|
||||
order_priority: (id, order_priority) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "order_priority", parseInt(order_priority || 0)),
|
||||
condition_id: (id, condition_id) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "condition_id", (condition_id && parseInt(condition_id) !== 0) ? parseInt(condition_id) : null),
|
||||
product: (id, product) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "product", parseInt(product)),
|
||||
lane: (id, lane) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "lane", parseInt(lane)),
|
||||
department: (id, department) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "department", parseInt(department)),
|
||||
machine_type_id: (id, machine_type_id) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "machine_type_id", (machine_type_id && parseInt(machine_type_id) !== 0) ? parseInt(machine_type_id) : null),
|
||||
product: (id, product) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "product", parseInt(product || 0)),
|
||||
lane: (id, lane) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "lane", parseInt(lane || 0)),
|
||||
department: (id, department) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "department", parseInt(department || 0)),
|
||||
services: (id, services) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "services", Array.isArray(services) ? services : []),
|
||||
buttons: (id, buttons) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "buttons", Array.isArray(buttons) ? buttons.map(b => parseInt(b)) : []),
|
||||
dynamic_images_vehicle_type: (id, vehicleType) => ObjectsGlobal.set.column(SelfServeTasks.meta.endpoint, id, "dynamic_images_vehicle_type", vehicleType ? parseInt(vehicleType) : null),
|
||||
@@ -251,40 +310,46 @@ export const SelfServeTasks = {
|
||||
functions: {
|
||||
getTaskText: getTaskText,
|
||||
formatTaskName: async (taskId) => {
|
||||
const [tasks, departments, products] = await Promise.all([
|
||||
SessionUser.objects.self_serve_tasks.get.all(),
|
||||
SessionUser.objects.departments.get.all(),
|
||||
SessionUser.objects.products.get.all()
|
||||
]);
|
||||
const tasks = await SessionUser.objects.self_serve_tasks.get.all();
|
||||
const task = tasks.find(t => parseInt(t.id) === parseInt(taskId));
|
||||
if (!task) return SessionUser.objects.global.language.no_data;
|
||||
|
||||
const departmentName = departments.find(d => parseInt(d.id) === parseInt(task.department))?.name || task.department;
|
||||
const productName = products.find(p => parseInt(p.id) === parseInt(task.product))?.name || task.product;
|
||||
return buildScopedTaskName(task);
|
||||
},
|
||||
getScopeLabel: async (task) => {
|
||||
if (task.machine_type_id) {
|
||||
const machineTypeName = await SessionUser.objects.self_serve_machine_types.functions.getMachineTypeName(task.machine_type_id);
|
||||
return `Maskintype: ${machineTypeName}`;
|
||||
}
|
||||
|
||||
return `${departmentName}-${task.lane}-${productName}: ${task.task}`;
|
||||
if (
|
||||
parseInt(task.department || 0) === 0
|
||||
&& parseInt(task.lane || 0) === 0
|
||||
&& parseInt(task.product || 0) === 0
|
||||
) {
|
||||
return "Fælles";
|
||||
}
|
||||
|
||||
return `Afdeling ${task.department || 0} / Bane ${task.lane || 0} / Køretøjstype ${task.product || 0}`;
|
||||
},
|
||||
showDeleteObjectForm: (id, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showDeleteObjectForm(SelfServeTasks, id, onAfterSubmit);
|
||||
},
|
||||
},
|
||||
/**
|
||||
* Show the create object form
|
||||
* @param initialData
|
||||
* @param onAfterSubmit
|
||||
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
||||
*/
|
||||
showCreateObjectForm: (initialData = {}, onAfterSubmit = null) => {
|
||||
return ObjectsGlobal.showCreateObjectForm(SelfServeTasks, onAfterSubmit, initialData);
|
||||
return showSelfServeTaskForm({
|
||||
object: SelfServeTasks,
|
||||
initialData,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
showEditObjectForm: (record, onAfterSubmit = null) => {
|
||||
return showSelfServeTaskForm({
|
||||
object: SelfServeTasks,
|
||||
record,
|
||||
onAfterSubmit,
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Show the edit object field form
|
||||
* @param id
|
||||
* @param column
|
||||
* @param value
|
||||
* @param onAfterSubmit
|
||||
* @returns {Promise<SweetAlertResult<Awaited<any>>>}
|
||||
*/
|
||||
showEditObjectFieldForm: (id, column, value, onAfterSubmit = null, options = {}) => {
|
||||
return ObjectsGlobal.showEditObjectFieldForm(
|
||||
SelfServeTasks,
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { ObjectsGlobal } from "@/components/session/token/SessionUser/Objects/ObjectsGlobal.vue";
|
||||
import { SessionUser } from "@/components/session/token/SessionUser.vue";
|
||||
import {ref} from "vue";
|
||||
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
|
||||
|
||||
/**
|
||||
* Local vehicle conditions cache
|
||||
@@ -161,6 +162,16 @@ export const SelfServeVehicleConditions = {
|
||||
},
|
||||
single: async (id) => {
|
||||
return ObjectsGlobal.get.object(SelfServeVehicleConditions.meta.endpoint, id);
|
||||
},
|
||||
previewAllowed: async (laneId, reg) => {
|
||||
return authenticatedRequest("/department/selfserve/vehicle/allowed", "GET", {
|
||||
lane_id: parseInt(laneId),
|
||||
reg: reg,
|
||||
}).then((response) => response.data.data || response.data);
|
||||
},
|
||||
washSummary: async (params = {}) => {
|
||||
return authenticatedRequest("/department/selfserve/washes/summary", "GET", params)
|
||||
.then((response) => response.data.data || response.data);
|
||||
}
|
||||
},
|
||||
delete: async (id) => {
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
<script>
|
||||
import {authenticatedRequest} from "@/components/session/authenticatedRequest.vue";
|
||||
|
||||
const normalizeEntries = (entries) => {
|
||||
if (Array.isArray(entries)) {
|
||||
return entries;
|
||||
}
|
||||
|
||||
if (entries && typeof entries === "object") {
|
||||
return Object.values(entries);
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
const toConfigPayload = (entries) => {
|
||||
const payload = {};
|
||||
normalizeEntries(entries).forEach((entry) => {
|
||||
if (!entry || !entry.variable) {
|
||||
return;
|
||||
}
|
||||
payload[entry.variable] = entry.value;
|
||||
});
|
||||
return payload;
|
||||
};
|
||||
|
||||
/**
|
||||
* The Self Serve -> Config object
|
||||
*/
|
||||
@@ -13,16 +36,29 @@ export const Config = {
|
||||
get_all: async () => {
|
||||
return authenticatedRequest(
|
||||
"/selfserve/config",
|
||||
"GET")
|
||||
"GET").then((response) => {
|
||||
const normalizedEntries = normalizeEntries(response?.data?.data);
|
||||
response.data.data = normalizedEntries;
|
||||
response.data.config = toConfigPayload(normalizedEntries);
|
||||
return response;
|
||||
});
|
||||
},
|
||||
set: async ( variable, value ) => {
|
||||
get_config: async () => {
|
||||
return Config.get_all().then((response) => response?.data?.config || {});
|
||||
},
|
||||
set_config: async (payload) => {
|
||||
return authenticatedRequest(
|
||||
"/selfserve/config",
|
||||
"POST",
|
||||
{
|
||||
variable: variable,
|
||||
value: value
|
||||
})
|
||||
payload
|
||||
);
|
||||
},
|
||||
set: async ( variable, value ) => {
|
||||
const currentConfig = await Config.get_config();
|
||||
return Config.set_config({
|
||||
...currentConfig,
|
||||
[variable]: value
|
||||
});
|
||||
},
|
||||
keys: {
|
||||
minute_product: {
|
||||
@@ -44,4 +80,4 @@ export const Config = {
|
||||
},
|
||||
};
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -127,6 +127,8 @@ import DepartmentSelfServeConditionRules
|
||||
from "@/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeConditionRules.vue";
|
||||
import DepartmentSelfServeVehicleConditions
|
||||
from "@/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeVehicleConditions.vue";
|
||||
import DepartmentSelfServeMachineTypes
|
||||
from "@/views/dashboards/departmentDashboard/modules/self-serve/DepartmentSelfServeMachineTypes.vue";
|
||||
import DepartmentGoals
|
||||
from "@/views/dashboards/departmentDashboard/modules/goals/DepartmentGoals.vue";
|
||||
import ConfigurationLimble from "@/views/dashboards/superUserDashboard/configuration/ConfigurationLimble.vue";
|
||||
@@ -548,6 +550,12 @@ export const router = createRouter({
|
||||
component: DepartmentSelfServeVehicleConditions,
|
||||
meta: { middleware: adminMiddleware, departmentSelection: true }
|
||||
},
|
||||
{
|
||||
name: 'selfservemachinetypes',
|
||||
path: '/admin/:departmentId/modules/self-serve/machine-types',
|
||||
component: DepartmentSelfServeMachineTypes,
|
||||
meta: { middleware: adminMiddleware, departmentSelection: true }
|
||||
},
|
||||
{
|
||||
name: 'superuser',
|
||||
path: '/superuser',
|
||||
|
||||
-12
@@ -39,18 +39,6 @@ const conditionId = route.query.condition_id;
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.condition_rules.add_question_rule') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_condition_rules.showCreateObjectForm({
|
||||
condition_id: conditionId,
|
||||
object_type: 'task'
|
||||
}, loadList)"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-tasks"></i>
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.condition_rules.add_task_rule') }}</span>
|
||||
</button>
|
||||
<button
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_condition_rules.showCreateObjectForm({
|
||||
|
||||
+7
-3
@@ -40,10 +40,8 @@ const selectVehicleType = (vehicleType) => {
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_conditions.showCreateObjectForm({
|
||||
department: departmentId,
|
||||
product: selectedVehicleType?.id,
|
||||
product: selectedVehicleType?.id || 0,
|
||||
}, loadList)"
|
||||
:disabled="!selectedVehicleType"
|
||||
:title="!selectedVehicleType ? t('admin.self_serve.select_vehicle_type_first') : ''"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-plus"></i>
|
||||
@@ -62,6 +60,12 @@ const selectVehicleType = (vehicleType) => {
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.tasks.manage') }}</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservemachinetypes', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-cubes"></i>
|
||||
</span>
|
||||
<span>Maskintyper</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservevehicleconditions', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-car-side"></i>
|
||||
|
||||
+6
-6
@@ -41,12 +41,8 @@ const selectVehicleType = (vehicleType) => {
|
||||
<button
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_questions.showCreateObjectForm({
|
||||
department: departmentId,
|
||||
product: selectedVehicleType?.id,
|
||||
order_priority: totalItems + 1
|
||||
}, loadList)"
|
||||
:disabled="!selectedVehicleType"
|
||||
:title="!selectedVehicleType ? t('admin.self_serve.select_vehicle_type_first') : ''"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-plus"></i>
|
||||
@@ -65,6 +61,12 @@ const selectVehicleType = (vehicleType) => {
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.tasks.manage') }}</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservemachinetypes', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-cubes"></i>
|
||||
</span>
|
||||
<span>Maskintyper</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservevehicleconditions', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-car-side"></i>
|
||||
@@ -74,8 +76,6 @@ const selectVehicleType = (vehicleType) => {
|
||||
<button
|
||||
class="button is-warning is-light"
|
||||
@click="showTryModal = true"
|
||||
:disabled="!selectedVehicleType"
|
||||
:title="!selectedVehicleType ? t('admin.self_serve.select_vehicle_type_first') : ''"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-play"></i>
|
||||
|
||||
+7
-3
@@ -40,11 +40,9 @@ const selectVehicleType = (vehicleType) => {
|
||||
class="button is-primary"
|
||||
@click="SessionUser.objects.self_serve_tasks.showCreateObjectForm({
|
||||
department: departmentId,
|
||||
product: selectedVehicleType?.id,
|
||||
product: selectedVehicleType?.id || 0,
|
||||
order_priority: totalItems + 1
|
||||
}, loadList)"
|
||||
:disabled="!selectedVehicleType"
|
||||
:title="!selectedVehicleType ? t('admin.self_serve.select_vehicle_type_first') : ''"
|
||||
>
|
||||
<span class="icon">
|
||||
<i class="fas fa-plus"></i>
|
||||
@@ -63,6 +61,12 @@ const selectVehicleType = (vehicleType) => {
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.questions.manage') }}</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservemachinetypes', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-cubes"></i>
|
||||
</span>
|
||||
<span>Maskintyper</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservevehicleconditions', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-car-side"></i>
|
||||
|
||||
+12
@@ -62,6 +62,18 @@ const regFilter = ref("");
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.questions.manage') }}</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservetasks', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-tasks"></i>
|
||||
</span>
|
||||
<span>{{ t('admin.self_serve.tasks.manage') }}</span>
|
||||
</router-link>
|
||||
<router-link :to="{ name: 'selfservemachinetypes', params: { departmentId: departmentId } }" class="button is-link is-light">
|
||||
<span class="icon">
|
||||
<i class="fas fa-cubes"></i>
|
||||
</span>
|
||||
<span>Maskintyper</span>
|
||||
</router-link>
|
||||
</div>
|
||||
</template>
|
||||
</SelfServeVehicleConditionsPagination>
|
||||
|
||||
Reference in New Issue
Block a user