Commit c43b6388 authored by Julien BOUYER's avatar Julien BOUYER
Browse files

UNOTOPLYS-172 feat(screen) : suppression des écrans

parent 445e1a82
import Vue from 'vue'; import Vue from 'vue';
import { Component } from 'vue-property-decorator'; import { Component, Inject } from 'vue-property-decorator';
import ScreenService from '@/entities/screen/screen.service';
import Icon from '@/components/icon/icon.vue'; import Icon from '@/components/icon/icon.vue';
import { IScreen } from '@/shared/model/screen.model';
@Component({ @Component({
components: { components: {
...@@ -9,6 +12,8 @@ import Icon from '@/components/icon/icon.vue'; ...@@ -9,6 +12,8 @@ import Icon from '@/components/icon/icon.vue';
}, },
}) })
export default class Panel extends Vue { export default class Panel extends Vue {
@Inject('screenService') private screenService: () => ScreenService;
public get screenList(): boolean { public get screenList(): boolean {
return this.$store.getters.screenList; return this.$store.getters.screenList;
} }
...@@ -41,4 +46,36 @@ export default class Panel extends Vue { ...@@ -41,4 +46,36 @@ export default class Panel extends Vue {
}); });
} }
} }
public deleteScreen() {
const idScreen = this.$store.getters.idScreen;
const idxScreen = this.$store.getters.screenList.findIndex((s: IScreen) => s.id === idScreen);
this.screenService()
.delete(idScreen)
.then(res => {
this.reload(idxScreen);
})
.catch(console.error);
}
public reload(idxScreen: number) {
const screenList = this.$store.getters.screenList;
screenList.splice(idxScreen, 1);
let screen: IScreen;
if (idxScreen === screenList.length) {
screen = screenList[screenList.length - 1];
} else {
screen = screenList[idxScreen];
}
if (screen) {
this.$router.push({
name: 'ScreenEditComponent',
params: {
idWorkspace: this.$store.getters.idWorkspace,
idForm: this.$store.getters.idForm,
idScreen: `${screen.id}`,
},
});
}
}
} }
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<icon name="add" /> <icon name="add" />
<span class="ml-2">{{ $t('screen.add') }}</span> <span class="ml-2">{{ $t('screen.add') }}</span>
</router-link> </router-link>
<button class="flex items-center p-2 text-red-600 transition hover:bg-red-600 focus:ring hover:text-red-100"> <button class="flex items-center p-2 text-red-600 transition hover:bg-red-600 focus:ring hover:text-red-100" @click="deleteScreen">
<icon name="trash" /> <icon name="trash" />
</button> </button>
</div> </div>
......
import { Module } from 'vuex'; import { Module } from 'vuex';
import FormService from '@/entities/form/form.service';
import ScreenService from '@/entities/screen/screen.service'; import ScreenService from '@/entities/screen/screen.service';
const formService = new FormService();
const screenService = new ScreenService(); const screenService = new ScreenService();
export const formStore: Module<any, any> = { export const formStore: Module<any, any> = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment