Sidebar.vue 13.2 KB
Newer Older
1
<template>
2
3
<aside :class="['ui', 'vertical', 'left', 'visible', 'wide', {'collapsed': isCollapsed}, 'sidebar',]">
  <header class="ui inverted segment header-wrapper">
4
    <search-bar @search="isCollapsed = false">
5
      <router-link :title="'Funkwhale'" :to="{name: logoUrl}">
6
7
8
        <i class="logo bordered inverted orange big icon">
          <logo class="logo"></logo>
        </i>
9
      </router-link><span
10
11
12
13
        slot="after"
        @click="isCollapsed = !isCollapsed"
        :class="['ui', 'basic', 'big', {'inverted': isCollapsed}, 'orange', 'icon', 'collapse', 'button']">
          <i class="sidebar icon"></i></span>
14
    </search-bar>
15
  </header>
16
17
18

  <div class="menu-area">
    <div class="ui compact fluid two item inverted menu">
19
20
      <a class="active item" role="button" @click.prevent.stop="selectedTab = 'library'" data-tab="library"><translate>Browse</translate></a>
      <a class="item" role="button" @click.prevent.stop="selectedTab = 'queue'" data-tab="queue">
21
        <translate>Queue</translate>&nbsp;
22
         <template v-if="queue.tracks.length === 0">
23
           <translate>(empty)</translate>
24
         </template>
Eliot Berriot's avatar
Eliot Berriot committed
25
26
27
         <translate v-else :translate-params="{index: queue.currentIndex + 1, length: queue.tracks.length}">
          (%{ index } of %{ length })
         </translate>
28
29
30
      </a>
    </div>
  </div>
Eliot Berriot's avatar
Eliot Berriot committed
31
  CECI EST UN TEST
32
  <div class="tabs">
33
34
    <section class="ui bottom attached active tab" data-tab="library" :aria-label="labels.mainMenu">
      <nav class="ui inverted vertical large fluid menu" role="navigation" :aria-label="labels.mainMenu">
35
        <div class="item">
36
          <header class="header"><translate>My account</translate></header>
37
          <div class="menu">
Eliot Berriot's avatar
Eliot Berriot committed
38
39
40
41
42
            <router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'profile', params: {username: $store.state.auth.username}}">
              <i class="user icon"></i>
              <translate :translate-params="{username: $store.state.auth.username}">
                Logged in as %{ username }
              </translate>
43
              <img class="ui right floated circular tiny avatar image" v-if="$store.state.auth.profile.avatar.square_crop" :src="$store.getters['instance/absoluteUrl']($store.state.auth.profile.avatar.square_crop)" />
Eliot Berriot's avatar
Eliot Berriot committed
44
            </router-link>
45
            <router-link class="item" v-if="$store.state.auth.authenticated" :to="{path: '/settings'}"><i class="setting icon"></i><translate>Settings</translate></router-link>
46
47
48
49
50
51
52
53
            <router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'notifications'}">
              <i class="feed icon"></i>
              <translate>Notifications</translate>
              <div
                v-if="$store.state.ui.notifications.inbox > 0"
                :class="['ui', 'teal', 'label']">
                {{ $store.state.ui.notifications.inbox }}</div>
            </router-link>
54
            <router-link class="item" v-if="$store.state.auth.authenticated" :to="{name: 'logout'}"><i class="sign out icon"></i><translate>Logout</translate></router-link>
emillumine's avatar
emillumine committed
55
56
57
            <template v-else>
              <router-link class="item" :to="{name: 'login'}"><i class="sign in icon"></i><translate>Login</translate></router-link>
              <router-link class="item" :to="{path: '/signup'}">
Eliot Berriot's avatar
Eliot Berriot committed
58
                <i class="corner add icon"></i>
emillumine's avatar
emillumine committed
59
60
61
                <translate>Create an account</translate>
              </router-link>
            </template>
62
63
64
          </div>
        </div>
        <div class="item">
65
          <header class="header"><translate>Music</translate></header>
66
          <div class="menu">
67
            <router-link class="item" :to="{path: '/library'}"><i class="sound icon"></i><translate>Browse library</translate></router-link>
68
            <router-link class="item" v-if="$store.state.auth.authenticated" :to="{path: '/favorites'}"><i class="heart icon"></i><translate>Favorites</translate></router-link>
69
70
71
72
            <a
              @click="$store.commit('playlists/chooseTrack', null)"
              v-if="$store.state.auth.authenticated"
              class="item">
73
              <i class="list icon"></i><translate>Playlists</translate>
74
            </a>
75
76
77
            <router-link
              v-if="$store.state.auth.authenticated"
              class="item" :to="{name: 'content.index'}"><i class="upload icon"></i><translate>Add content</translate></router-link>
78
79
          </div>
        </div>
80
        <div class="item" v-if="$store.state.auth.availablePermissions['settings']">
81
          <header class="header"><translate>Administration</translate></header>
82
          <div class="menu">
83
84
85
            <router-link
              class="item"
              :to="{path: '/manage/settings'}">
86
              <i class="settings icon"></i><translate>Settings</translate>
87
            </router-link>
Eliot Berriot's avatar
Eliot Berriot committed
88
89
            <router-link
              class="item"
90
              :to="{name: 'manage.users.users.list'}">
91
              <i class="users icon"></i><translate>Users</translate>
Eliot Berriot's avatar
Eliot Berriot committed
92
            </router-link>
93
94
          </div>
        </div>
95
96
      </nav>
    </section>
97
98
99
100
    <div v-if="queue.previousQueue " class="ui black icon message">
      <i class="history icon"></i>
      <div class="content">
        <div class="header">
101
          <translate>Do you want to restore your previous queue?</translate>
102
        </div>
Eliot Berriot's avatar
Eliot Berriot committed
103
104
105
106
107
108
109
110
        <p>
          <translate
            translate-plural="%{ count } tracks"
            :translate-n="queue.previousQueue.tracks.length"
            :translate-params="{count: queue.previousQueue.tracks.length}">
            %{ count } track
          </translate>
        </p>
111
        <div class="ui two buttons">
112
113
          <div @click="queue.restore()" class="ui basic inverted green button"><translate>Yes</translate></div>
          <div @click="queue.removePrevious()" class="ui basic inverted red button"><translate>No</translate></div>
114
115
116
        </div>
      </div>
    </div>
117
    <section class="ui bottom attached tab" data-tab="queue">
118
      <table class="ui compact inverted very basic fixed single line unstackable table">
119
        <draggable v-model="tracks" element="tbody" @update="reorder">
120
121
122
123
124
          <tr
              @click="$store.dispatch('queue/currentIndex', index)"
              v-for="(track, index) in tracks"
              :key="index"
              :class="[{'active': index === queue.currentIndex}]">
125
126
              <td class="right aligned">{{ index + 1}}</td>
              <td class="center aligned">
127
                  <img class="ui mini image" v-if="track.album.cover && track.album.cover.original" :src="$store.getters['instance/absoluteUrl'](track.album.cover.small_square_crop)">
128
129
130
                  <img class="ui mini image" v-else src="../assets/audio/default-cover.png">
              </td>
              <td colspan="4">
131
                  <button class="title reset ellipsis" :aria-label="labels.selectTrack">
132
133
134
                    <strong>{{ track.title }}</strong><br />
                    {{ track.artist.name }}
                  </button>
135
136
              </td>
              <td>
137
                <template v-if="$store.getters['favorites/isFavorite'](track.id)">
138
                  <i class="pink heart icon"></i>
139
                </template>
140
141
              </td>
              <td>
142
                  <button :title="labels.removeFromQueue" @click.stop="cleanTrack(index)" :class="['ui', {'inverted': index != queue.currentIndex}, 'really', 'tiny', 'basic', 'circular', 'icon', 'button']">
143
144
                    <i class="trash icon"></i>
                  </button>
145
146
147
              </td>
            </tr>
          </draggable>
148
      </table>
149
      <div v-if="$store.state.radios.running" class="ui black message">
150
151
        <div class="content">
          <div class="header">
152
            <i class="feed icon"></i> <translate>You have a radio playing</translate>
153
          </div>
154
155
          <p><translate>New tracks will be appended here automatically.</translate></p>
          <div @click="$store.dispatch('radios/stop')" class="ui basic inverted red button"><translate>Stop radio</translate></div>
156
157
        </div>
      </div>
158
    </section>
159
  </div>
160
  <player @next="scrollToCurrent" @previous="scrollToCurrent"></player>
161
</aside>
162
163
164
</template>

<script>
165
import { mapState, mapActions } from "vuex"
166

167
168
169
170
171
import Player from "@/components/audio/Player"
import Logo from "@/components/Logo"
import SearchBar from "@/components/audio/SearchBar"
import backend from "@/audio/backend"
import draggable from "vuedraggable"
172

173
import $ from "jquery"
174
175

export default {
176
  name: "sidebar",
177
178
179
  components: {
    Player,
    SearchBar,
180
    Logo,
181
    draggable
182
  },
183
  data() {
184
    return {
185
      selectedTab: "library",
186
      backend: backend,
187
      tracksChangeBuffer: null,
188
      isCollapsed: true,
189
      fetchInterval: null
190
191
    }
  },
192
193
194
195
  mounted() {
    $(this.$el)
      .find(".menu .item")
      .tab()
196
  },
197
  destroy() {
198
199
200
201
    if (this.fetchInterval) {
      clearInterval(this.fetchInterval)
    }
  },
202
203
  computed: {
    ...mapState({
204
205
      queue: state => state.queue,
      url: state => state.route.path
206
    }),
207
208
209
210
211
    labels() {
      let mainMenu = this.$gettext("Main menu")
      let selectTrack = this.$gettext("Play this track")
      let pendingRequests = this.$gettext("Pending import requests")
      let pendingFollows = this.$gettext("Pending follow requests")
Eliot Berriot's avatar
Eliot Berriot committed
212
213
      return {
        pendingRequests,
214
215
216
        pendingFollows,
        mainMenu,
        selectTrack
Eliot Berriot's avatar
Eliot Berriot committed
217
218
      }
    },
219
    tracks: {
220
      get() {
221
222
        return this.$store.state.queue.tracks
      },
223
      set(value) {
224
225
        this.tracksChangeBuffer = value
      }
226
    },
227
    logoUrl() {
228
      if (this.$store.state.auth.authenticated) {
229
        return "library.index"
230
      } else {
231
        return "index"
232
      }
233
    }
234
  },
235
  methods: {
236
    ...mapActions({
237
      cleanTrack: "queue/cleanTrack"
238
    }),
239
240
241
242
243
244
    reorder: function(event) {
      this.$store.commit("queue/reorder", {
        tracks: this.tracksChangeBuffer,
        oldIndex: event.oldIndex,
        newIndex: event.newIndex
      })
245
    },
246
    scrollToCurrent() {
247
248
249
250
      let current = $(this.$el).find('[data-tab="queue"] .active')[0]
      if (!current) {
        return
      }
251
      let container = $(this.$el).find(".tabs")[0]
252
253
254
255
256
      // Position container at the top line then scroll current into view
      container.scrollTop = 0
      current.scrollIntoView(true)
      // Scroll back nothing if element is at bottom of container else do it
      // for half the height of the containers display area
257
258
259
260
      var scrollBack =
        container.scrollHeight - container.scrollTop <= container.clientHeight
          ? 0
          : container.clientHeight / 2
261
      container.scrollTop = container.scrollTop - scrollBack
262
    }
263
264
  },
  watch: {
265
    url: function() {
266
      this.isCollapsed = true
267
    },
268
269
    selectedTab: function(newValue) {
      if (newValue === "queue") {
270
271
272
        this.scrollToCurrent()
      }
    },
273
274
    "$store.state.queue.currentIndex": function() {
      if (this.selectedTab !== "queue") {
275
276
        this.scrollToCurrent()
      }
277
    }
278
279
280
281
282
283
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
284
@import "../style/vendor/media";
285

286
$sidebar-color: #3d3e3f;
287
288

.sidebar {
289
  background: $sidebar-color;
290
  @include media(">tablet") {
291
292
    display: flex;
    flex-direction: column;
293
294
295
296
    justify-content: space-between;
  }
  @include media(">desktop") {
    .collapse.button {
297
      display: none !important;
298
299
300
301
302
303
    }
  }
  @include media("<desktop") {
    position: static !important;
    width: 100% !important;
    &.collapsed {
304
305
306
      .menu-area,
      .player-wrapper,
      .tabs {
307
308
309
310
        display: none;
      }
    }
  }
311
312
313
314
315

  > div {
    margin: 0;
    background-color: $sidebar-color;
  }
316
317
  .menu.vertical {
    background: $sidebar-color;
318
319
320
321
322
  }
}

.menu-area {
  .menu .item:not(.active):not(:hover) {
Bat's avatar
Bat committed
323
    opacity: 0.75;
324
325
  }

326
327
328
329
330
331
332
  .menu .item {
    border-radius: 0;
  }

  .menu .item.active {
    background-color: $sidebar-color;
    &:hover {
333
      background-color: rgba(255, 255, 255, 0.06);
334
335
    }
  }
336
}
337
338
339
.vertical.menu {
  .item .item {
    font-size: 1em;
340
341
342
343
344
345
346
    > i.icon {
      float: none;
      margin: 0 0.5em 0 0;
    }
    &:not(.active) {
      color: rgba(255, 255, 255, 0.75);
    }
347
348
  }
}
349
.tabs {
350
351
352
  flex: 1;
  display: flex;
  flex-direction: column;
353
  overflow-y: auto;
354
  justify-content: space-between;
355
  @include media("<desktop") {
356
    max-height: 500px;
357
  }
358
}
359
360
361
.ui.tab.active {
  display: flex;
}
362
.tab[data-tab="queue"] {
363
  flex-direction: column;
364
365
366
  tr {
    cursor: pointer;
  }
Renon's avatar
Renon committed
367
368
369
  td:nth-child(2) {
    width: 55px;
  }
370
}
371
372
373
374
375
376
377
378
379
380
381
.tab[data-tab="library"] {
  flex-direction: column;
  flex: 1 1 auto;
  > .menu {
    flex: 1;
    flex-grow: 1;
  }
  > .player-wrapper {
    width: 100%;
  }
}
382
383
384
385
386
387
388
389
390
391
392
393
.sidebar .segment {
  margin: 0;
  border-radius: 0;
}

.ui.inverted.segment.header-wrapper {
  padding: 0;
}

.logo {
  cursor: pointer;
  display: inline-block;
Bat's avatar
Bat committed
394
  margin: 0px;
395
396
397
}

.ui.search {
Bat's avatar
Bat committed
398
  display: flex;
399

400
401
402
  .collapse.button,
  .collapse.button:hover,
  .collapse.button:active {
403
404
405
406
407
    box-shadow: none !important;
    margin: 0px;
    display: flex;
    flex-direction: column;
    justify-content: center;
408
  }
409
}
Bat's avatar
Bat committed
410

Bat's avatar
Bat committed
411
412
413
.ui.message.black {
  background: $sidebar-color;
}
Renon's avatar
Renon committed
414
415
416
417

.ui.mini.image {
  width: 100%;
}
Bat's avatar
Bat committed
418
419
420
421
422
423
424
425
426
427
428
</style>

<style lang="scss">
.sidebar {
  .ui.search .input {
    flex: 1;
    .prompt {
      border-radius: 0;
    }
  }
}
429
.ui.tiny.avatar.image {
Eliot Berriot's avatar
Eliot Berriot committed
430
431
  position: relative;
  top: -0.5em;
432
  width: 3em;
Eliot Berriot's avatar
Eliot Berriot committed
433
}
434
435
436
437

:not(.active) button.title {
  outline-color: white;
}
438
</style>