You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
4.8 KiB

  1. <template>
  2. <v-app>
  3. <the-header>
  4. <template #leftDrawerIcon>
  5. <v-app-bar-nav-icon @click="drawerLeft = !drawerLeft" />
  6. </template>
  7. </the-header>
  8. <v-navigation-drawer
  9. v-model="drawerLeft"
  10. app
  11. clipped
  12. color=""
  13. >
  14. <the-side-bar
  15. :link="getLink"
  16. :role="getCurrentUserRole"
  17. />
  18. </v-navigation-drawer>
  19. <v-main>
  20. <v-overlay :value="loading">
  21. <v-progress-circular indeterminate size="64" />
  22. </v-overlay>
  23. <v-container fluid>
  24. <v-row
  25. no-gutters
  26. class="d-none d-sm-flex"
  27. >
  28. <v-col>
  29. <approve-button
  30. v-if="canViewApproveButton"
  31. :approved="approved"
  32. :disabled="currentDoc ? false : true"
  33. />
  34. <filter-button
  35. v-model="filterOption"
  36. />
  37. <guideline-button />
  38. </v-col>
  39. <v-spacer />
  40. <v-col>
  41. <pagination
  42. v-model="page"
  43. :length="total"
  44. />
  45. </v-col>
  46. </v-row>
  47. <v-row justify="center">
  48. <v-col cols="12" md="9">
  49. <nuxt />
  50. </v-col>
  51. <v-col cols="12" md="3">
  52. <metadata-box
  53. v-if="currentDoc && !loading"
  54. :metadata="JSON.parse(currentDoc.meta)"
  55. />
  56. </v-col>
  57. </v-row>
  58. </v-container>
  59. </v-main>
  60. <bottom-navigator
  61. v-model="page"
  62. :length="total"
  63. class="d-flex d-sm-none"
  64. />
  65. </v-app>
  66. </template>
  67. <script>
  68. import { mapActions, mapGetters, mapState, mapMutations } from 'vuex'
  69. import BottomNavigator from '@/components/containers/annotation/BottomNavigator'
  70. import GuidelineButton from '@/components/containers/annotation/GuidelineButton'
  71. import MetadataBox from '@/components/organisms/annotation/MetadataBox'
  72. import FilterButton from '@/components/containers/annotation/FilterButton'
  73. import ApproveButton from '@/components/containers/annotation/ApproveButton'
  74. import Pagination from '~/components/containers/annotation/Pagination'
  75. import TheHeader from '~/components/organisms/layout/TheHeader'
  76. import TheSideBar from '~/components/organisms/layout/TheSideBar'
  77. export default {
  78. middleware: ['check-auth', 'auth', 'set-project'],
  79. components: {
  80. TheSideBar,
  81. TheHeader,
  82. BottomNavigator,
  83. Pagination,
  84. GuidelineButton,
  85. FilterButton,
  86. ApproveButton,
  87. MetadataBox
  88. },
  89. fetch() {
  90. this.getDocumentList({
  91. projectId: this.$route.params.id,
  92. limit: this.limit,
  93. offset: this.offset,
  94. q: this.$route.query.q,
  95. isChecked: this.filterOption,
  96. filterName: this.getFilterOption
  97. })
  98. },
  99. data() {
  100. return {
  101. drawerLeft: null,
  102. limit: 10
  103. }
  104. },
  105. computed: {
  106. ...mapGetters('projects', ['getLink', 'getCurrentUserRole', 'getFilterOption', 'canViewApproveButton']),
  107. ...mapState('documents', ['loading', 'total']),
  108. ...mapGetters('documents', ['currentDoc', 'approved']),
  109. page: {
  110. get() {
  111. return parseInt(this.$route.query.page, 10)
  112. },
  113. set(value) {
  114. this.$router.push({
  115. query: {
  116. isChecked: this.$route.query.isChecked,
  117. page: parseInt(value, 10),
  118. q: this.$route.query.q
  119. }
  120. })
  121. }
  122. },
  123. filterOption: {
  124. get() {
  125. return this.$route.query.isChecked
  126. },
  127. set(value) {
  128. this.$router.push({
  129. query: {
  130. isChecked: value,
  131. page: 1,
  132. q: this.$route.query.q
  133. }
  134. })
  135. }
  136. },
  137. offset() {
  138. return Math.floor((this.page - 1) / this.limit) * this.limit
  139. },
  140. current() {
  141. return (this.page - 1) % this.limit
  142. },
  143. searchOptions() {
  144. // a bit tricky technique to capture variables change simultaneously.
  145. // see https://github.com/vuejs/vue/issues/844#issuecomment-265315349
  146. return JSON.stringify({
  147. page: this.page,
  148. q: this.$route.query.q,
  149. isChecked: this.filterOption
  150. })
  151. }
  152. },
  153. watch: {
  154. total() {
  155. // To validate the range of page variable on reloading the annotation page.
  156. if (this.total !== 0 && this.page > this.total) {
  157. this.$router.push({
  158. path: this.localePath(`/projects/${this.$route.params.id}/`)
  159. })
  160. }
  161. },
  162. offset() {
  163. this.$fetch()
  164. },
  165. filterOption() {
  166. this.page = 1
  167. this.$fetch()
  168. },
  169. current: {
  170. handler() {
  171. this.setCurrent(this.current)
  172. },
  173. immediate: true
  174. },
  175. searchOptions() {
  176. this.saveSearchOptions(JSON.parse(this.searchOptions))
  177. }
  178. },
  179. methods: {
  180. ...mapActions('documents', ['getDocumentList']),
  181. ...mapMutations('documents', ['setCurrent']),
  182. ...mapMutations('projects', ['saveSearchOptions'])
  183. }
  184. }
  185. </script>