UserNav.vue 16.6 KB
Newer Older
1
<template lang="pug">
2 3
  q-toolbar(color="dark", :class="{'q-pa-none': isMobile}", style="border-bottom: 1px solid #333;")

4 5 6 7
    // back button
    <!--q-btn(@click="goBack()", icon="keyboard_backspace", flat, no-ripple,-->
    <!--:class="{'back-button': !targetBackButton}")-->
      <!--q-chip(floating, color="transparent", text-color="primary") 2-->
8

9 10
    // menu button
    q-btn(@click="handlerMenuDrawer", icon="menu", flat)
11

12
    breadcrumb-nav(:timeline="timeline", :videoMetadata="videoMetadata", :grid="grid")
13

14 15
    // drawer
    q-layout-drawer.bg-dark(v-model="menuDrawer", content-class="bg-dark", overlay)
16

17 18
      // buttons component: apps
      button-list(v-bind:buttons="actions", :currentApp="currentApp", :currentId="[currentId]")
19

20
      q-item-separator.q-my-none
21

22 23
      // buttons component: user
      button-list(v-bind:buttons="activeUserButtons", :currentApp="currentApp", :currentId="[currentId]")
24

25 26 27 28
</template>

<script>
  import { mapGetters } from 'vuex'
29
  import { userHasFeature } from 'mbjs-quasar/src/lib'
30 31 32
  import { parseURI } from 'mbjs-data-models/src/lib'

  import ButtonList from './ButtonList'
33
  import BreadcrumbNav from './BreadcrumbNav'
34 35

  export default {
36
    components: {
37
      BreadcrumbNav,
38 39
      ButtonList
    },
40
    data () {
41
      const _this = this
42
      return {
43 44 45 46
        timeline: undefined,
        videoMetadata: undefined,
        grid: undefined,
        breadcrumbs: [],
47
        currentApp: null,
48 49 50 51 52 53 54 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 130 131 132 133 134 135 136 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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
        env: process.env,
        actions: [
          {
            rel: 'root',
            type: 'piecemaker',
            name: 'piecemaker.timelines.list',
            label: _this.$t('navigation.piecemaker.label'),
            // icon: 'reorder',
            icon: 'vertical_split',
            click: () => {
              this.currentId.timeline = undefined
              this.currentId.video = undefined
              this.currentId.grid = undefined
              _this.executeApp('piecemaker', 'piecemaker.timelines.list')
            },
            subactions: [
              {
                rel: 'parent',
                type: 'piecemaker',
                name: 'piecemaker.timelines.list',
                label: _this.$t('navigation.piecemaker.piecemaker_timelines_list'),
                click: () => {
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('piecemaker', 'piecemaker.timelines.list')
                },
                subactions: [
                  {
                    rel: 'child',
                    name: 'piecemaker.timelines.annotate',
                    label: _this.$t('navigation.piecemaker.piecemaker_timelines_annotate'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = undefined
                      this.$router.push({ name: 'piecemaker.timelines.annotate', params: { uuid: this.currentId.timeline } })
                    }
                  },
                  {
                    rel: 'child',
                    name: 'piecemaker.videos.list',
                    label: _this.$t('navigation.piecemaker.piecemaker_videos_list'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = undefined
                      this.$router.push({ name: 'piecemaker.videos.list', params: { timelineUuid: this.currentId.timeline } })
                    },
                    subactions: [
                      {
                        rel: 'grandchild',
                        name: 'piecemaker.videos.annotate',
                        label: _this.$t('navigation.piecemaker.piecemaker_videos_annotate'),
                        click: () => {
                          this.$router.push({ name: 'piecemaker.videos.annotate', params: { uuid: this.currentId.video } })
                        }
                      },
                      {
                        rel: 'grandchild',
                        name: 'piecemaker.videos.edit',
                        label: _this.$t('navigation.piecemaker.piecemaker_videos_edit'),
                        click: () => {
                          this.$router.push({ name: 'piecemaker.videos.edit', params: { uuid: this.currentId.video } })
                        }
                      },
                      {
                        rel: 'grandchild',
                        name: 'piecemaker.videos.sync',
                        label: _this.$t('navigation.piecemaker.piecemaker_videos_sync'),
                        click: () => {
                          this.$router.push({ name: 'piecemaker.videos.sync', params: { uuid: this.currentId.video } })
                        }
                      }
                    ]
                  },
                  {
                    rel: 'child',
                    name: 'piecemaker.timelines.search',
                    label: _this.$t('navigation.piecemaker.piecemaker_timelines_search'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = undefined
                      this.$router.push({ name: 'piecemaker.timelines.search', params: { uuid: this.currentId.timeline } })
                    }
                  },
                  {
                    rel: 'child',
                    name: 'piecemaker.timelines.edit',
                    label: _this.$t('navigation.piecemaker.piecemaker_timelines_edit'),
                    click: () => {
                      this.currentId.video = undefined
                      this.$router.push({ name: 'piecemaker.timelines.edit', params: { uuid: this.currentId.timeline } })
                    }
                  }
                ]
              },
              {
                rel: 'parent',
                type: 'piecemaker',
                name: 'piecemaker.timelines.create',
                label: _this.$t('navigation.piecemaker.piecemaker_timelines_create'),
                click: () => {
                  this.currentId.timeline = undefined
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('piecemaker', 'piecemaker.timelines.create')
                }
              }
            ]
          },
          {
            rel: 'root',
            type: 'mosys',
            name: 'mosys.grids.list',
            label: _this.$t('navigation.mosys.label'),
            icon: 'grid_on',
            click: () => {
              this.currentId.video = undefined
              this.currentId.grid = undefined
              _this.executeApp('mosys', 'mosys.grids.list')
            },
            subactions: [
              {
                rel: 'parent',
                type: 'mosys',
                name: 'mosys.grids.list',
                label: _this.$t('navigation.mosys.mosys_grids_list'),
                click: () => {
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('mosys', 'mosys.grids.list')
                },
                subactions: [
                  {
                    rel: 'child',
                    name: 'mosys.grids.annotate',
                    label: _this.$t('navigation.mosys.mosys_grids_annotate'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = this.$route.params.uuid
                      this.$router.push({ name: 'mosys.grids.annotate', params: { uuid: this.currentId.grid } })
                    }
                  },
                  {
                    rel: 'child',
                    name: 'mosys.grids.show',
                    label: _this.$t('navigation.mosys.mosys_grids_show'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = this.$route.params.uuid
                      this.$router.push({ name: 'mosys.grids.show', params: { uuid: this.currentId.grid } })
                    }
                  },
                  {
                    rel: 'child',
                    name: 'mosys.grids.edit',
                    label: _this.$t('navigation.mosys.mosys_grids_edit'),
                    click: () => {
                      this.currentId.video = undefined
                      this.currentId.grid = this.$route.params.uuid
                      this.$router.push({ name: 'mosys.grids.edit', params: { uuid: this.currentId.grid } })
                    }
                  }
                ]
              },
              {
                rel: 'parent',
                type: 'mosys',
                name: 'mosys.grids.create',
                label: _this.$t('navigation.mosys.mosys_grids_create'),
                click: () => {
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('mosys', 'mosys.grids.create')
                }
              }
            ]
          },
          {
            rel: 'root',
            type: 'mosys',
            name: 'documents.list',
            label: _this.$t('navigation.documents.label'),
            icon: 'attach_file',
            click: () => {
              this.currentId.video = undefined
              this.currentId.grid = undefined
              _this.executeApp('mosys', 'documents.list')
            },
            subactions: [
              {
                rel: 'parent',
                type: 'documents',
                name: 'documents.list',
                label: _this.$t('navigation.documents.documents_list'),
                click: () => {
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('documents', 'documents.list')
                },
                subactions: [
                  {
                    name: 'documents.edit',
                    label: _this.$t('navigation.documents.documents_edit'),
                    click: () => {
                      this.currentId.video = undefined
                      this.$router.push({ name: 'documents.edit' })
                    }
                  }
                ]
              },
              {
                rel: 'parent',
                type: 'documents',
                name: 'documents.create',
                label: 'Add Document',
                click: () => {
                  this.currentId.video = undefined
                  this.currentId.grid = undefined
                  _this.executeApp('documents', 'documents.create')
                }
              }
            ]
          }
        ],
271 272 273 274 275 276 277 278 279
        routes: {
          piecemaker: [
            'piecemaker.timelines.annotate',
            'piecemaker.timelines.edit',
            'piecemaker.timelines.search',
            'piecemaker.timelines.show',
            'piecemaker.videos.list'
          ]
        },
280 281 282 283 284 285 286 287
        activeUserButtons: [],
        targetBackButton: undefined,
        menuDrawer: false,
        currentId: {
          timeline: undefined,
          video: undefined,
          grid: undefined,
          documents: undefined
288
        }
289 290 291 292
      }
    },
    computed: {
      ...mapGetters({
293 294
        user: 'auth/getUserState',
        isMobile: 'globalSettings/getIsMobile'
295
      }),
Anton's avatar
Anton committed
296 297
      userHasDocuments () {
        return userHasFeature(this.user, 'documents')
298 299
      },
      isElectron () {
300
        return this.$q.platform.is.electron
301 302
      }
    },
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
    created () {
      this.$root.$on('setBackButton', this.setBackButton)
    },
    async mounted () {
      const _this = this

      // generate user related buttons depending on auth status
      const userButtons = [
        {
          rel: 'root',
          type: 'users',
          name: 'users.manage',
          icon: 'settings',
          // label: this.user.profile ? this.user.profile.name : ''},
          label: _this.$t('navigation.users.label'),
          click: () => _this.$router.push({ name: 'users.manage' }),
          query: [_this.user, !_this.isElectron],
          subactions: [
            {
              rel: 'parent',
              type: 'users',
              name: 'users.manage',
              // label: this.user.profile ? this.user.profile.name : ''},
              label: _this.$t('navigation.users.users_manage'),
              click: () => _this.$router.push({ name: 'users.manage' })
              // query: [_this.user, !_this.isElectron]
            }
          ]
        },
        {
          rel: 'root',
          type: 'log',
          name: 'log.logout',
          icon: 'eject',
          label: _this.$t('navigation.logout'),
          click: () => _this.logout(),
          query: [_this.user, !_this.isElectron]
        },
        {
          rel: 'root',
          type: 'log',
          name: 'log.login',
          icon: 'arrow_forward',
          label: _this.$t('navigation.login'),
          click: () => _this.login(),
          query: [!_this.user, !_this.isElectron]
        }
      ]
      let filteredUserButtons = userButtons.map(b => b.query.every(function (f) { if (f) return true }))
      filteredUserButtons.map((b, i) => {
        if (b) this.activeUserButtons.push(userButtons[i])
      })
      this.checkRoute(this.$route)
    },
    watch: {
      '$route' (route) {
        this.checkRoute(route)
      }
    },
362
    methods: {
363
      checkRoute (route) {
364 365 366 367
        this.timeline = undefined
        this.videoMetadata = undefined
        this.grid = undefined

368 369 370 371 372 373 374 375
        // detect current app
        let routeSplit = route.name.split('.')
        if (routeSplit[0] !== 'site') this.currentApp = routeSplit[0]
        else this.currentApp = 'Motionbank'

        // FIXME: find a better way to handle the navigation drawer highlighting

        // timeline
376
        if (this.routes.piecemaker.includes(route.name)) {
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
          if (route.params.timelineUuid) this.currentId.timeline = route.params.timelineUuid
          if (route.params.uuid) this.currentId.timeline = route.params.uuid
          this.currentId.video = undefined
          this.getTimeline()
        }

        // video
        if (route.name === 'piecemaker.videos.annotate' ||
          route.name === 'piecemaker.videos.edit' ||
          route.name === 'piecemaker.videos.sync'
        ) {
          this.currentId.video = route.params.uuid
          this.getVideo()
        }
        else {
          this.currentId.video = undefined
        }

        // grid
        if (route.name === 'mosys.grids.annotate' ||
          route.name === 'mosys.grids.show' ||
          route.name === 'mosys.grids.edit'
        ) {
          this.currentId.grid = route.params.uuid
          this.getGrid()
        }
        else {
          this.currentId.grid = undefined
        }
      },
      async getGrid () {
        this.grid = await this.$store.dispatch('maps/get', this.$route.params.uuid)
      },
      async getTimeline () {
        if (this.$route.params.timelineUuid) {
          this.timeline = await this.$store.dispatch('maps/get', this.$route.params.timelineUuid)
        }
        if (this.$route.params.uuid) {
          this.timeline = await this.$store.dispatch('maps/get', this.$route.params.uuid)
          if (!this.timeline) this.timeline = await this.$store.dispatch('maps/get', parseURI(this.video.target.id).uuid)
        }
      },
      async getVideo () {
        if (this.$route.params.uuid) {
          this.video = await this.$store.dispatch('annotations/get', this.$route.params.uuid)
          this.videoMetadata = await this.$store.dispatch('metadata/get', this.video)
          if (this.video && !this.currentId.timeline) this.currentId.timeline = parseURI(this.video.target.id).uuid
        }

        // set parent timeline from video when reloading in video submenu
        if (!this.timeline) {
          this.timeline = await this.$store.dispatch('maps/get', parseURI(this.video.target.id).uuid)
        }
      },
      handlerMenuDrawer () {
        this.menuDrawer = !this.menuDrawer
      },
      goBack () {
        return this.$router.push(this.targetBackButton)
      },
      setBackButton (val) {
        this.targetBackButton = val
      },
440
      executeApp (appName, routeName) {
441 442 443
        this.currentId.video = undefined
        this.currentId.timeline = undefined
        this.currentId.grid = undefined
444 445 446 447 448 449 450 451 452 453 454 455 456 457
        this.currentApp = appName
        this.$router.push({ name: routeName })
      },
      login () {
        this.$auth.authenticate()
      },
      logout () {
        this.$store.commit('auth/setUser', undefined)
        this.$auth.logout()
      }
    }
  }
</script>

458 459 460 461 462 463 464 465 466
<style lang="stylus" scoped>
  @import '~variables'

  .q-item-division + .q-item-separator
    border-top 1px solid $grey-9

  .back-button
    margin-left -52px
</style>