This commit is contained in:
2021-04-09 19:05:34 +00:00
parent 6f2676ecd2
commit 4da4b3331b
2 changed files with 57 additions and 41 deletions

View File

@@ -1,5 +1,5 @@
<template> <template>
<div v-if="pvm != null"> <div v-if="value != null">
selected row: {{ selectedRow }} selected row: {{ selectedRow }}
<!-- Title and menu --> <!-- Title and menu -->
<v-col cols="12"> <v-col cols="12">
@@ -31,14 +31,15 @@
</v-col> </v-col>
<!-- <!--
<span class="text-caption" <span class="text-caption"
>[selected su_index: {{ pvm.selectedScheduledUserItemIndex }}]</span >[selected su_index: {{ activeItemIndex }}]</span
> --> > -->
<template v-if="pvm.scheduledUserItemCount > 1"> <template v-if="showTable">
<!-- ################################ SCHEDULED USERS TABLE ############################### --> <!-- ################################ SCHEDULED USERS TABLE ############################### -->
<v-col cols="12"> <v-col cols="12">
<v-data-table <v-data-table
:headers="headerList" :headers="headerList"
:items="itemList" :items="itemList"
item-key="index"
v-model="selectedRow" v-model="selectedRow"
class="elevation-1" class="elevation-1"
disable-pagination disable-pagination
@@ -48,28 +49,19 @@
data-cy="scheduledUsersTable" data-cy="scheduledUsersTable"
dense dense
:item-class="itemRowClasses" :item-class="itemRowClasses"
item-key="index" @click:row="handleRowClick"
@click:row="selectItem"
:show-select="$vuetify.breakpoint.xs" :show-select="$vuetify.breakpoint.xs"
single-select single-select
> >
<!-- <template v-slot:[`item.actions`]="{ item }">
<v-btn icon @click="selectItem(item)">
<v-icon :class="itemRowClasses(item)">
$ayiEdit
</v-icon>
</v-btn>
</template> -->
</v-data-table> </v-data-table>
</v-col> </v-col>
</template> </template>
<template v-if="pvm.hasSelectedScheduledUserItem"> <template v-if="activeItemIndex != null">
<v-col cols="12" sm="6" lg="4" xl="3"> <v-col cols="12" sm="6" lg="4" xl="3">
<gz-decimal <gz-decimal
v-model=" v-model="
value.items[pvm.selectedItemIndex].scheduledUsers[ value.items[activeWoItemIndex].scheduledUsers[activeItemIndex]
pvm.selectedScheduledUserItemIndex .estimatedQuantity
].estimatedQuantity
" "
:readonly="formState.readOnly" :readonly="formState.readOnly"
:label="$ay.t('WorkOrderItemScheduledUserEstimatedQuantity')" :label="$ay.t('WorkOrderItemScheduledUserEstimatedQuantity')"
@@ -78,8 +70,8 @@
:error-messages=" :error-messages="
form().serverErrors( form().serverErrors(
this, this,
`Items[${pvm.selectedItemIndex}].scheduledUsers[ `Items[${activeWoItemIndex}].scheduledUsers[
${pvm.selectedScheduledUserItemIndex} ${activeItemIndex}
].estimatedQuantity` ].estimatedQuantity`
) )
" "
@@ -88,8 +80,8 @@
form().required(this, 'scheduledUsers.EstimatedQuantity') form().required(this, 'scheduledUsers.EstimatedQuantity')
]" ]"
@input=" @input="
fieldValueChanged(`Items[${pvm.selectedItemIndex}].scheduledUsers[ fieldValueChanged(`Items[${activeWoItemIndex}].scheduledUsers[
${pvm.selectedScheduledUserItemIndex} ${activeItemIndex}
].estimatedQuantity`) ].estimatedQuantity`)
" "
></gz-decimal> ></gz-decimal>
@@ -109,9 +101,11 @@
*/ */
export default { export default {
data() { data() {
return { selectedRow: [] }; return {
activeItemIndex: null,
selectedRow: []
};
}, },
props: { props: {
value: { value: {
default: null, default: null,
@@ -120,15 +114,18 @@ export default {
pvm: { pvm: {
default: null, default: null,
type: Object type: Object
},
activeWoItemIndex: {
default: null,
type: Number
} }
}, },
methods: { methods: {
newItem() { newItem() {
let newIndex = this.value.items[this.pvm.selectedItemIndex].scheduledUsers let newIndex = this.value.items[this.activeWoItemIndex].scheduledUsers
.length; .length;
this.value.items[this.pvm.selectedItemIndex].scheduledUsers.push({ this.value.items[this.activeWoItemIndex].scheduledUsers.push({
id: 0, id: 0,
concurrency: 0, concurrency: 0,
userId: null, userId: null,
@@ -137,29 +134,45 @@ export default {
stopDate: null, stopDate: null,
serviceRateId: null, serviceRateId: null,
isDirty: true, isDirty: true,
workOrderItemId: this.value.items[this.pvm.selectedItemIndex].id workOrderItemId: this.value.items[this.activeWoItemIndex].id
}); });
this.pvm.setDirty(); this.$emit("change");
this.pvm.selectedScheduledUserItemIndex = newIndex; this.selectedRow = [{ index: newIndex }];
this.activeItemIndex = newIndex;
}, },
async deleteItem() { async deleteItem() {
if ((await window.$gz.dialog.confirmDelete()) != true) { if ((await window.$gz.dialog.confirmDelete()) != true) {
return; return;
} }
this.value.items[this.pvm.selectedItemIndex].scheduledUsers.splice(
this.pvm.selectedScheduledUserItemIndex, let o = this.value.items[this.activeWoItemIndex].scheduledUsers[
this.activeItemIndex
];
if (o.id != 0) {
//it's a previously saved item so it needs to be removed at the server too
this.$emit("graph-item-deleted", {
atype: window.$gz.type.WorkOrderItemScheduledUser,
id: o.id
});
}
this.value.items[this.activeWoItemIndex].scheduledUsers.splice(
this.activeItemIndex,
1 1
); );
if (this.pvm.scheduledUserItemCount > 0) {
this.pvm.selectedScheduledUserItemIndex = //if only one record left then display it otherwise just let the datatable show what the user can click on
this.pvm.scheduledUserItemCount - 1; if (this.value.items[this.activeWoItemIndex].scheduledUsers.length == 1) {
this.selectedRow = [{ index: 0 }];
this.activeItemIndex = 0;
} else { } else {
this.pvm.selectedScheduledUserItemIndex = null; this.selectedRow = [];
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
} }
}, },
selectItem: function(item) { handleRowClick: function(item) {
this.selectedRow = [item]; this.activeItemIndex = item.index;
this.pvm.selectedScheduledUserItemIndex = item.index; this.selectedRow = [{ index: item.index }];
}, },
form() { form() {
return window.$gz.form; return window.$gz.form;
@@ -167,8 +180,8 @@ export default {
fieldValueChanged(ref) { fieldValueChanged(ref) {
if (!this.formState.loading && !this.formState.readonly) { if (!this.formState.loading && !this.formState.readonly) {
//flag this record dirty so it gets picked up by save //flag this record dirty so it gets picked up by save
this.value.items[this.pvm.selectedItemIndex].scheduledUsers[ this.value.items[this.activeWoItemIndex].scheduledUsers[
this.pvm.selectedScheduledUserItemIndex this.activeItemIndex
].isDirty = true; ].isDirty = true;
window.$gz.form.fieldValueChanged(this.pvm, ref); window.$gz.form.fieldValueChanged(this.pvm, ref);
} }
@@ -254,7 +267,7 @@ IN ORDER: start, stop, quantity, user, rate
return headers; return headers;
}, },
itemList: function() { itemList: function() {
return this.value.items[this.pvm.selectedItemIndex].scheduledUsers.map( return this.value.items[this.activeWoItemIndex].scheduledUsers.map(
(x, i) => { (x, i) => {
return { return {
index: i, index: i,
@@ -287,6 +300,9 @@ IN ORDER: start, stop, quantity, user, rate
formCustomTemplateKey: function() { formCustomTemplateKey: function() {
return this.pvm.formCustomTemplateKey; return this.pvm.formCustomTemplateKey;
}, },
showTable: function() {
return this.value.items[this.activeWoItemIndex].scheduledUsers.length > 1;
},
canAdd: function() { canAdd: function() {
return ( return (
!this.value.isLockedAtServer && !this.value.isLockedAtServer &&

View File

@@ -1,6 +1,5 @@
<template> <template>
<div v-if="value != null"> <div v-if="value != null">
selected row: {{ selectedRow }}
<!-- Title and menu --> <!-- Title and menu -->
<v-col cols="12"> <v-col cols="12">
<v-menu offset-y> <v-menu offset-y>
@@ -84,6 +83,7 @@
v-if="pvm.subRights.scheduledUsers.visible" v-if="pvm.subRights.scheduledUsers.visible"
v-model="value" v-model="value"
:pvm="pvm" :pvm="pvm"
:active-wo-item-index="activeItemIndex"
data-cy="woItemScheduledUsers" data-cy="woItemScheduledUsers"
/> />
</template> </template>