index.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <style lang="scss" scoped>
  2. @import '~/assets/styles/_colors.scss';
  3. section { background-color: $backgroundLight1 !important; }
  4. section.hero div.hero-body {
  5. align-items: baseline;
  6. }
  7. .albumsModal .columns .column { padding: .25rem; }
  8. </style>
  9. <template>
  10. <section class="hero is-fullheight">
  11. <div class="hero-body">
  12. <div class="container">
  13. <div class="columns">
  14. <div class="column is-narrow">
  15. <Sidebar />
  16. </div>
  17. <div class="column">
  18. <h2 class="subtitle">Your uploaded files</h2>
  19. <hr>
  20. <!-- TODO: Add a list view so the user can see the files that don't have thumbnails, like text documents -->
  21. <Grid v-if="files.length"
  22. :files="files" />
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. <b-modal :active.sync="isAlbumsModalActive"
  28. :width="640"
  29. scroll="keep">
  30. <div class="card albumsModal">
  31. <div class="card-content">
  32. <div class="content">
  33. <h3 class="subtitle">Select the albums this file should be a part of</h3>
  34. <hr>
  35. <div class="columns is-multiline">
  36. <div v-for="(album, index) in albums"
  37. :key="index"
  38. class="column is-3">
  39. <div class="field">
  40. <b-checkbox :value="isAlbumSelected(album.id)"
  41. @input="albumCheckboxClicked($event, album.id)">{{ album.name }}</b-checkbox>
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. </b-modal>
  49. </section>
  50. </template>
  51. <script>
  52. import Sidebar from '~/components/sidebar/Sidebar.vue';
  53. import Grid from '~/components/grid/Grid.vue';
  54. export default {
  55. components: {
  56. Sidebar,
  57. Grid
  58. },
  59. data() {
  60. return {
  61. files: [],
  62. albums: [],
  63. isAlbumsModalActive: false,
  64. showingModalForFile: null
  65. };
  66. },
  67. computed: {
  68. config() {
  69. return this.$store.state.config;
  70. }
  71. },
  72. metaInfo() {
  73. return { title: 'Uploads' };
  74. },
  75. mounted() {
  76. this.getFiles();
  77. this.getAlbums();
  78. },
  79. methods: {
  80. isAlbumSelected(id) {
  81. if (!this.showingModalForFile) return;
  82. const found = this.showingModalForFile.albums.find(el => el.id === id);
  83. return found ? found.id ? true : false : false;
  84. },
  85. openAlbumModal(file) {
  86. this.showingModalForFile = file;
  87. this.isAlbumsModalActive = true;
  88. },
  89. async albumCheckboxClicked(value, id) {
  90. try {
  91. const response = await this.axios.post(`${this.config.baseURL}/file/album/${value ? 'add' : 'del'}`, {
  92. albumId: id,
  93. fileId: this.showingModalForFile.id
  94. });
  95. this.$toast.open(response.data.message);
  96. // Not the prettiest solution to refetch on each click but it'll do for now
  97. this.getFiles();
  98. } catch (error) {
  99. this.$onPromiseError(error);
  100. }
  101. },
  102. async getFiles() {
  103. try {
  104. const response = await this.axios.get(`${this.config.baseURL}/files`);
  105. this.files = response.data.files;
  106. } catch (error) {
  107. console.error(error);
  108. }
  109. },
  110. async getAlbums() {
  111. try {
  112. const response = await this.axios.get(`${this.config.baseURL}/albums/dropdown`);
  113. this.albums = response.data.albums;
  114. } catch (error) {
  115. this.$onPromiseError(error);
  116. }
  117. }
  118. }
  119. };
  120. </script>