diff --git a/canapGEST/API/app/Http/Controllers/PositionsController.php b/canapGEST/API/app/Http/Controllers/PositionsController.php index 094f3fe766b410035e4dbb612f856b30cc92b373..ec488fc49cccbe8ac1cdfe02a3dcb88249f631e7 100644 --- a/canapGEST/API/app/Http/Controllers/PositionsController.php +++ b/canapGEST/API/app/Http/Controllers/PositionsController.php @@ -108,7 +108,8 @@ class PositionsController extends Controller $has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable'); - $position_access_groups = $this->request->input('access_groups'); + $position_access_groups = $this->request->input('access_group_cleared'); + $position_access_groups_to_create = $this->request->input('new_groups'); $position_spot_number = $this->request->input('position_spot_number'); $location_id = $this->request->input('location_id'); $job_id = $this->request->input('job_id'); @@ -116,7 +117,6 @@ class PositionsController extends Controller $wanted_position_exists = DB::table('position')->where('position_id', $id)->exists(); if ($wanted_position_exists && $has_permitted_role) { - // TODO: new value for access group ? DB::table('position')->where('position_id', $id)->update([ "position_spot_number" => $position_spot_number, "fk_location" => $location_id, @@ -134,6 +134,16 @@ class PositionsController extends Controller ]); } + foreach ($position_access_groups_to_create as $group) { + DB::table('access_group')->insertGetId([ + "access_group_value" => $group + ]); + DB::table('has_access')->insert([ + "fk_access_group" => $group, + "fk_position" => $id + ]); + } + return ["message" => lang::get('http.success.updated.position'), "id" => $id]; } else { return response()->json(['error' => 403, 'message' => lang::get('http.unauthorized')], 403); @@ -142,7 +152,6 @@ class PositionsController extends Controller public function deletePosition($id) { $has_permitted_role = AccessLevelHelper::hasPermittedRole($this->user_role, 'responsable'); - $wanted_position_exists = DB::table('position')->where('position_id', $id)->exists(); $wanted_position_in_use = DB::table('applicant')->where('fk_position', $id)->exists(); @@ -150,6 +159,7 @@ class PositionsController extends Controller if ($wanted_position_in_use) { return response()->json(['error' => 403, 'message' => lang::get('http.error.deleted.position')], 403); } else { + DB::table('has_access')->where('fk_position', $id)->delete(); DB::table('position')->where('position_id', $id)->delete(); return ["message" => lang::get('http.success.deleted.position')]; } diff --git a/canapGEST/Site/src/store/modules/positions/actions.js b/canapGEST/Site/src/store/modules/positions/actions.js index 15bad32f7e319919a3c4ac4e8dd35d3a8eb875c2..9858b794ac685c68741a891bfd18a70eda42aa77 100644 --- a/canapGEST/Site/src/store/modules/positions/actions.js +++ b/canapGEST/Site/src/store/modules/positions/actions.js @@ -62,25 +62,39 @@ export function createPosition(context, data) { } export function updatePosition(context, data) { - axios({ - method: 'patch', - url: '/position/' + data.position_id, - data: data + data.new_groups = [] + data.access_group_cleared = [] + data.access_groups.forEach(group => { + if (!group.access_group_value) { + data.new_groups.push(group) + } else { + data.access_group_cleared.push(group) + } }) - .then(response => { - context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true }) + return new Promise(resolve => { + axios({ + method: 'patch', + url: '/position/' + data.position_id, + data: data }) + .then(response => { + context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true }) + resolve() + }) + }) } export function deletePosition(context, data) { - axios({ - method: 'delete', - url: '/position/' + data.position_id, - data: data - }) - .then(response => { - context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true }) + return new Promise(resolve => { + axios({ + method: 'delete', + url: '/position/' + data.position_id }) + .then(response => { + context.commit('moduleSnackbar/toggle', { open: true, message: response.data.message, type: 'success' }, { root: true }) + resolve() + }) + }) } export function createJob(context, data) { diff --git a/canapGEST/Site/src/views/OpenJobsView.vue b/canapGEST/Site/src/views/OpenJobsView.vue index 960b595360f2b68ac70891a1a66b93b4dc5f596e..79746eac82b6b8c0cbf1fd5e5dc1315e97d4f6a3 100644 --- a/canapGEST/Site/src/views/OpenJobsView.vue +++ b/canapGEST/Site/src/views/OpenJobsView.vue @@ -1,7 +1,7 @@ <template> <div id="openjobs-view"> <h1>Places ouvertes</h1> - <template> + <template v-if="loaded"> <div> <v-toolbar flat color="white"> <v-spacer></v-spacer> @@ -93,10 +93,10 @@ <template v-slot:items="props"> <td>{{ props.item.job_full_value }}</td> <td>{{ props.item.location_site }}</td> - <!-- <td + <td v-if="props.item.access_groups.length > 1" - >{{ props.item.access_groups[0].access_group_value }} + {{props.item.access_groups.length-1}} autre(s) groupes(s)</td>--> - <!-- <td v-else>{{props.item.access_groups[0].access_group_value }}</td> --> + >{{ props.item.access_groups[0].access_group_value }} + {{props.item.access_groups.length-1}} autre(s) groupes(s)</td> + <td v-else>{{props.item.access_groups[0].access_group_value }}</td> <td>{{ props.item.position_spot_number }}</td> <td> <v-icon class="mr-2" @click="editItem(props.item)">edit</v-icon> @@ -114,6 +114,7 @@ export default { name: 'openjobs-view', data() { return { + loaded: false, dialog: false, addJob: false, addLocation: false, @@ -162,14 +163,17 @@ export default { } }, created() { - this.loadData() + this.loadData().then(this.loaded = true) }, methods: { loadData() { - this.$store.dispatch('modulePositions/getPositions') - this.$store.dispatch('modulePositions/getJobs') - this.$store.dispatch('modulePositions/getLocations') - this.$store.dispatch('modulePositions/getAccessGroups') + return new Promise(resolve => { + this.$store.dispatch('modulePositions/getPositions') + this.$store.dispatch('modulePositions/getJobs') + this.$store.dispatch('modulePositions/getLocations') + this.$store.dispatch('modulePositions/getAccessGroups') + resolve() + }) }, editItem(item) { this.editedIndex = item.position_id @@ -178,8 +182,7 @@ export default { }, deleteItem(item) { if (confirm('Voulez-vous vraiment supprimer cette offre ?')) { - this.$store.dispatch('modulePositions/deletePosition', item) - this.loadData() + this.$store.dispatch('modulePositions/deletePosition', item).then(setTimeout(() => { this.loadData() }, 300)) } }, close() { @@ -194,13 +197,13 @@ export default { save() { if (this.editedIndex != -1) { // Edit - this.$store.dispatch('modulePositions/updatePosition', this.editedItem) + this.$store.dispatch('modulePositions/updatePosition', this.editedItem).then(setTimeout(() => { this.loadData() }, 300)) } else { // create - this.$store.dispatch('modulePositions/createPosition', this.editedItem) + this.$store.dispatch('modulePositions/createPosition', this.editedItem).then(setTimeout(() => { this.loadData() }, 300)) } this.close() - setTimeout(() => { this.loadData() }, 300) + // setTimeout(() => { this.loadData() }, 300) }, addNewJob() { if (this.addJob) {