ProjectTemplates.vue 2.42 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<template>
  <crud-list
    class="mt-2"
    :title="$t('template.plural')"
    :button="crudListButton"
    :items="crudListItems"
    :paginated="false"
  />
</template>

<script>
import store from '@/store';
import { mapState, mapGetters, mapActions } from 'vuex';
import RequiresManagerMixin from '@/mixins/RequiresManagerMixin';
15
import TextHelpersMixin from '@/mixins/TextHelpersMixin';
16
17
18
19
20
21
import CrudList from '@/components/crud/CrudList';

export default {
  name: 'ProjectTemplates',
  mixins: [
    RequiresManagerMixin,
22
    TextHelpersMixin,
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
  ],
  components: {
    CrudList,
  },
  computed: {
    ...mapState('template', {
      publicTemplates: 'publicList',
      projectTemplates: 'projectList',
    }),
    ...mapGetters('project', ['isManager', 'projectId']),
    crudListButton() {
      return {
        isDisplayed: this.isManager,
        to: `/projects/${this.projectId}/templates/create`,
        text: this.$t('template.create'),
      };
    },
    crudListItems() {
      const templates = [
        ...this.publicTemplates,
        ...this.projectTemplates,
      ];
      const scopes = [
        'base',
        'global',
        'project',
        'set',
      ];
      return templates.map((template) => ({
        id: template.id,
        name: this.textTruncate(template.name, 50),
54
        status: {
55
56
57
58
          label: this.$t(`template.scopes.${scopes[template.scope - 1]}`),
        },
        updatedAt: template.updatedAt,
        // Pount v2 : Manager can publish templates
59
        // actions: [
60
61
62
63
64
65
        //   {
        //     disabled: template.scope < 2,
        //     name: 'publish',
        //     icon: 'mdi-share-variant',
        //   },
        // ],
66
67
68
69
70
71
72
        to: {
          name: 'projectTemplate',
          params: {
            projectId: this.projectId,
            templateId: template.id,
          }
        }
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
      }));
    },
  },
  methods: {
    ...mapActions('template', ['loadProjectTemplates']),
    onPagination(pagination){
      this.loadProjectTemplates({ page: pagination.page, size: pagination.itemsPerPage});
    },
    // onPublish(templateId) {
    //   console.log(`Publishing ${templateId}`);
    // },
  },
  beforeRouteEnter(to, from, next) {
    const loadPublicTemplate = store.dispatch('template/loadPublicTemplates');
    const loadProjectTemplates = store.dispatch('template/loadProjectTemplates');

    Promise.all([loadPublicTemplate, loadProjectTemplates]).then(() => next());
  },
};
</script>