Merged in feature/PMCORE-3917 (pull request #8519)

PMCORE-3917

Approved-by: Rodrigo Quelca
Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Fabio Guachalla
2022-08-29 14:13:49 +00:00
committed by Julio Cesar Laura Avendaño
4 changed files with 168 additions and 2 deletions

View File

@@ -285,6 +285,7 @@
></i> ></i>
</b-button> </b-button>
</div> </div>
<div slot="sort"><i class="fa fa-align-justify handle sort-handle"></i></div>
</v-client-table> </v-client-table>
</b-form-group> </b-form-group>
</b-col> </b-col>
@@ -307,13 +308,17 @@
</template> </template>
<script> <script>
import Multiselect from "vue-multiselect"; import Multiselect from "vue-multiselect";
import draggable from "vuedraggable";
import eventBus from "../../../home/EventBus/eventBus";
import Api from "./Api/CaseList"; import Api from "./Api/CaseList";
import IconPicker from "../../../components/iconPicker/IconPicker.vue"; import IconPicker from "../../../components/iconPicker/IconPicker.vue";
import ModalPreview from "../../Modals/ModalPreview.vue"; import ModalPreview from "../../Modals/ModalPreview.vue";
import _ from 'lodash';
export default { export default {
name: "CaseListSketh", name: "CaseListSketh",
components: { components: {
draggable,
Multiselect, Multiselect,
IconPicker, IconPicker,
IconPicker, IconPicker,
@@ -322,6 +327,8 @@ export default {
props: ["params", "module"], props: ["params", "module"],
data() { data() {
return { return {
enabled: true,
dragging: false,
icon: "fas fa-user-cog", icon: "fas fa-user-cog",
isLoading: false, isLoading: false,
isButtonDisabled: false, isButtonDisabled: false,
@@ -349,6 +356,7 @@ export default {
texts: { texts: {
count: "", count: "",
}, },
isDraggable: false,
}, },
dataCaseList: [], dataCaseList: [],
columnsCaseList: [ columnsCaseList: [
@@ -359,6 +367,7 @@ export default {
"typeSearch", "typeSearch",
"enableFilter", "enableFilter",
"action", "action",
"sort",
], ],
caseListOptions: { caseListOptions: {
headings: { headings: {
@@ -368,6 +377,7 @@ export default {
typeSearch: this.$i18n.t("ID_TYPE_OF_SEARCHING"), typeSearch: this.$i18n.t("ID_TYPE_OF_SEARCHING"),
enableFilter: this.$i18n.t("ID_ENABLE_SEARCH_FILTER"), enableFilter: this.$i18n.t("ID_ENABLE_SEARCH_FILTER"),
action: "", action: "",
sort: "",
}, },
filterable: false, filterable: false,
perPage: 1000, perPage: 1000,
@@ -376,6 +386,7 @@ export default {
texts: { texts: {
count: "", count: "",
}, },
isDraggable: true,
}, },
defaultCaseList: [], defaultCaseList: [],
isValidName: null, isValidName: null,
@@ -390,10 +401,15 @@ export default {
}, },
}, },
mounted() { mounted() {
let that = this;
this.getDefaultColumns(this.module.key); this.getDefaultColumns(this.module.key);
if(this.params.id) { if(this.params.id) {
this.editMode(); this.editMode();
} }
eventBus.$on("sort-case-list", (data) => {
that.sortCaseList(data);
});
}, },
methods: { methods: {
/** /**
@@ -745,6 +761,12 @@ export default {
disabledField(field){ disabledField(field){
const fields = [ "due_date" , "process_category" , "process_name" , "priority" ]; const fields = [ "due_date" , "process_category" , "process_name" , "priority" ];
return !(fields.indexOf(field) == -1); return !(fields.indexOf(field) == -1);
},
sortCaseList(data) {
let auxList = _.cloneDeep(this.dataCaseList);
let aux = auxList.splice(data.oldIndex, 1);
auxList.splice(data.newIndex, 0, aux[0]);
this.dataCaseList = auxList;
} }
}, },
}; };
@@ -781,4 +803,7 @@ export default {
.invalid .typo__label { .invalid .typo__label {
color: #f04124; color: #f04124;
} }
.sort-handle {
color: gray
}
</style> </style>

View File

@@ -4,6 +4,7 @@ import VueSidebarMenu from "vue-sidebar-menu";
import VueI18n from 'vue-i18n'; import VueI18n from 'vue-i18n';
import { BootstrapVue } from 'bootstrap-vue'; import { BootstrapVue } from 'bootstrap-vue';
import { ServerTable, Event, ClientTable} from 'vue-tables-2'; import { ServerTable, Event, ClientTable} from 'vue-tables-2';
import VtTableBody from '../../../components/vuetable/extends/VtTableBody';
import "@fortawesome/fontawesome-free/css/all.css"; import "@fortawesome/fontawesome-free/css/all.css";
import 'bootstrap/dist/css/bootstrap-grid.css'; import 'bootstrap/dist/css/bootstrap-grid.css';
import 'bootstrap/dist/css/bootstrap.min.css' import 'bootstrap/dist/css/bootstrap.min.css'
@@ -18,7 +19,9 @@ Vue.use(VueSidebarMenu);
Vue.use(BootstrapVue); Vue.use(BootstrapVue);
Vue.use(VueI18n); Vue.use(VueI18n);
Vue.use(ServerTable, {}, false, 'bootstrap3', {}); Vue.use(ServerTable, {}, false, 'bootstrap3', {});
Vue.use(ClientTable, {}, false, 'bootstrap3', {}); Vue.use(ClientTable, {}, false, 'bootstrap3', {
tableBody: VtTableBody
});
window.ProcessMaker = { window.ProcessMaker = {
apiClient: require('axios') apiClient: require('axios')
}; };

View File

@@ -0,0 +1,84 @@
<template>
<draggable
tag="tbody"
v-if="props.opts.isDraggable"
v-model="props.data"
handle=".handle"
@end="checkMove"
@start="dragging = true"
>
<vnodes :vnodes="props.slots.prependBody"/>
<vt-no-results-row v-if="props.data.length === 0"/>
<table-rows v-for="(row,index) in props.data"
:row="row"
:index="props.initialIndex + index + 1"
:renderChildRow="props.hasChildRow && props.openChildRows.includes(row[props.uniqueRowId])"
:key="index"
/>
<vnodes :vnodes="props.slots.appendBody"/>
</draggable>
<tbody v-else>
<vnodes :vnodes="props.slots.prependBody"/>
<vt-no-results-row v-if="props.data.length === 0"/>
<table-rows v-for="(row,index) in props.data"
:row="row"
:index="props.initialIndex + index + 1"
:renderChildRow="props.hasChildRow && props.openChildRows.includes(row[props.uniqueRowId])"
:key="index"
/>
<vnodes :vnodes="props.slots.appendBody"/>
</tbody>
</template>
<script>
import draggable from "vuedraggable";
import eventBus from "../../../home/EventBus/eventBus";
import VtNoResultsRow from 'vue-tables-2/compiled/components/VtNoResultsRow'
import VtTableRow from 'vue-tables-2/compiled/components/VtTableRow'
import VtChildRow from 'vue-tables-2/compiled/components/VtChildRow'
export default {
name: "MyTableBody",
props: ['props'],
components: {
draggable,
VtNoResultsRow,
VtTableRow,
VtChildRow,
vnodes: {
functional: true,
render: (h, ctx) => ctx.props.vnodes
},
TableRows: {
functional: true,
render(h, ctx) {
let props = ctx.data.attrs,
data = [
h('vt-table-row', {
props
})
];
if (props.renderChildRow) {
data.push(h('vt-child-row', {
props
}))
}
return data
}
}
},
data() {
return {
enabled: true,
dragging: false,
}
},
methods: {
checkMove (e) {
this.dragging = false;
eventBus.$emit("sort-case-list", e);
}
}
}
</script>

View File

@@ -172,6 +172,8 @@ class CaseList extends Model
} }
$attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']); $attributes['CAL_COLUMNS'] = json_encode($attributes['CAL_COLUMNS']);
self::checkColumnsConfigurationChanges($id, $attributes['CAL_TYPE'], $attributes['CAL_COLUMNS']);
$caseList = CaseList::where('CAL_ID', '=', $id); $caseList = CaseList::where('CAL_ID', '=', $id);
$caseList->update($attributes); $caseList->update($attributes);
$model = $caseList->get()->first(); $model = $caseList->get()->first();
@@ -181,6 +183,45 @@ class CaseList extends Model
return $model; return $model;
} }
/**
* Check if the columns configuration has changed.
* @param int $calId
* @param string $type
* @param string $newColumns
* @return void
*/
private function checkColumnsConfigurationChanges(int $calId, string $type, string $newColumns): void
{
$caseList = CaseList::where('CAL_ID', '=', $calId)->first();
if ($caseList->CAL_COLUMNS === $newColumns) {
return;
}
$listUserConfig = UserConfig::where('USC_NAME', '=', 'userConfig')
->select()
->get();
foreach ($listUserConfig as $userConfig) {
if (empty($userConfig->USC_SETTING)) {
continue;
}
$uscSetting = json_decode($userConfig->USC_SETTING);
if (!property_exists($uscSetting, $type)) {
continue;
}
if (!property_exists($uscSetting->{$type}, 'customCaseList')) {
continue;
}
if (!property_exists($uscSetting->{$type}->customCaseList, $calId)) {
continue;
}
if (!property_exists($uscSetting->{$type}->customCaseList->{$calId}, 'columns')) {
continue;
}
$uscSetting->{$type}->customCaseList->{$calId}->columns = ['detail', 'actions'];
UserConfig::editSetting($userConfig->USR_ID, 'userConfig', (array) $uscSetting);
}
}
/** /**
* Delete this model. * Delete this model.
* @param int $id * @param int $id
@@ -523,7 +564,7 @@ class CaseList extends Model
//merge with stored information //merge with stored information
$result = []; $result = [];
foreach ($default as &$column) { foreach ($default as &$column) {
foreach ($storedColumns as $storedColumn) { foreach ($storedColumns as $keyStoredColumn => $storedColumn) {
if (!is_object($storedColumn)) { if (!is_object($storedColumn)) {
continue; continue;
} }
@@ -538,12 +579,25 @@ class CaseList extends Model
if (isset($storedColumn['set'])) { if (isset($storedColumn['set'])) {
$column['set'] = $storedColumn['set']; $column['set'] = $storedColumn['set'];
} }
//for column ordering, this will be removed later
$column['sortIndex'] = $keyStoredColumn;
break; break;
} }
} }
$result[] = $column; $result[] = $column;
} }
//sort columns by 'sortIndex', then 'sortIndex' will be removed.
$n = count($result);
usort($result, function ($a, $b) use ($n) {
$a1 = isset($a['sortIndex']) ? $a['sortIndex'] : $n;
$b1 = isset($b['sortIndex']) ? $b['sortIndex'] : $n;
return $a1 - $b1;
});
foreach ($result as &$value) {
unset($value['sortIndex']);
}
return $result; return $result;
} }