UsersTable.vue 5.26 KB
Newer Older
Anton's avatar
Anton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 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
<template lang="pug">

  div.shadow-3(style="padding: 1rem;")

    q-modal(v-model="openModal")
      div.bg-black.q-pa-lg.row
        h5.no-margin.no-padding.col-12 Send an invitation

        form-main.col-12(
          :schema="schemaMail"
          )

        // .text-center
          q-btn(@click="openModal = false") Abort

    div.q-px-md
      h5.light-paragraph
        | {{ headl }}
        span.float-right
          q-btn(@click="openModal = true") Add user

      q-data-table(
        @rowclick="onRowClick($event)",
        :dark="true",
        :data="users",
        :config="conf",
        :columns="cols",
        :actions="actns"
        )

        template(slot="col-name", slot-scope="cell")
          template(v-for="c in cell")
            // span(v-if="c.status") {{ c.name }}
            | {{ c.name }}

        template.text-center(slot="col-confirmed", slot-scope="cell")
          div.text-center(v-if="cell.data")
            q-icon(name="done")

        template(slot="col-action", slot-scope="cell")
          q-btn(
            flat,
            small,
            v-for="a in actions",
            :color="a.color || 'neutral'",
            :key="a.type",
            @click="action(a.type, cell, a.scope)"
            ) {{ $t(a.title) }}

</template>

<script>
53 54
  import FormMain from './FormMain'
  import Username from '../elements/Username'
Anton's avatar
Anton committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
  import { DateTime } from 'luxon'
  import constants from '../../../lib/constants'
  import { required } from 'vuelidate/lib/validators'

  export default {
    components: {
      Username,
      FormMain
    },
    // props: ['entries', 'config', 'columns', 'actions'],
    props: ['columns', 'actions', 'headline'],
    data () {
      const _this = this
      const defaultConfig = {
        rowHeight: '50px',
        noHeader: false,
        leftStickyColumns: 0,
        rightStickyColumns: 0,
        bodyStyle: {
        },
        messages: {
          noData: _this.$t('table.no_data'),
          noDataAfterFiltering: _this.$t('table.no_data_in_filter')
        }
      }
      const cols = this.columns.map(column => {
        return Object.assign({
          filter: false,
          sort: false
        }, column)
      })
      cols.push({
        field: 'action',
        classes: 'text-right'
      })
      const context = this
      return {
        openModal: false,
        rows: [],
        conf: Object.assign(defaultConfig, _this.config),
        cols: cols,
        headl: _this.headline,
        actns: _this.actions,
        users: [{
          name: 'Christian Hansen',
          mail: 'ch@motionbank.org',
          confirmed: true
        }, {
          name: 'Marlon Brando',
          mail: 'info@motionbank.org',
          confirmed: true
        }, {
          name: 'Johnny Cash',
          mail: 'jc@motionbank.org',
          confirmed: false
        }, {
          name: 'Donald Duck',
          mail: 'dd@motionbank.org',
          confirmed: true
        }],
        schemaMail: {
          fields: {
            title: {
              fullWidth: true,
              type: 'text',
              label: 'Enter mail address',
              errorLabel: 'errors.field_required',
              validators: {
                required
              }
            }
          },
          submit: {
            handler () {
              context.payload.author = context.$store.state.auth.payload.userId
130
              if (!context.$route.params.uuid) {
131
                context.payload.type = [constants.mapTypes.MAP_TYPE_TIMELINE]
Anton's avatar
Anton committed
132 133 134
              }
              return Promise.resolve()
                .then(() => {
135 136
                  if (context.payload._uuid) {
                    return context.$store.dispatch('maps/patch', [context.payload._uuid, context.payload])
Anton's avatar
Anton committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                  }
                  return context.$store.dispatch('maps/create', context.payload)
                })
                .then(() => {
                  if (context.redirectTo) {
                    context.$router.push(context.redirectTo)
                  }
                })
            }
          }
        }
      }
    },
    methods: {
      onRowClick (target) {
        this.$emit('row-click', target)
      },
      action (type, target, scope) {
        // this.$emit('action', type, target)
        const _this = this
        // const hl = this.headline
        switch (type) {
        case 'edit':
            // return _this.$router.push({ name: 'piecemaker.timelines.user' })
          if (scope === 'grid') {
            return _this.$router.push({ name: 'mosys.grids.user' })
          }
          else if (scope === 'timeline') {
            return _this.$router.push({ name: 'piecemaker.timelines.user' })
          }
        }
      },
      updateEntries () {
        const _this = this
        if (this.entries instanceof Promise) {
          this.entries.then(entries => {
            _this.rows = entries
          })
        }
        else {
          _this.rows = this.entries
        }
      },
      formatDateTime (data) {
        return DateTime.fromISO(data).toLocaleString(DateTime.DATETIME_SHORT_WITH_SECONDS)
      }
    },
    mounted () {
      this.updateEntries()
    },
    watch: {
      entries () {
        this.updateEntries()
      }
    }
  }
</script>

<style>
  .inactive {
    opacity: .5!important;
    background-color: red;
    }
</style>