Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Add bookmarks #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/api/context.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { fetchJSON } from './utils'

export async function get () {
return await fetchJSON(`/api/context`, {})
}
12 changes: 12 additions & 0 deletions src/api/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ export async function post (url, content = '', overwrite = false, onupload) {
})
}

export function bookmark (items) {
let promises = []

for (let item of items) {
const path = removePrefix(item.path)
const url = `${path}?action=${item.bookmarked ? 'bookmark' : 'remove-bookmark'}`
promises.push(resourceAction(url, 'PATCH'))
}

return Promise.all(promises)
}

function moveCopy (items, copy = false) {
let promises = []

Expand Down
4 changes: 3 additions & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as files from './files'
import * as share from './share'
import * as users from './users'
import * as settings from './settings'
import * as context from './context'
import search from './search'
import commands from './commands'

Expand All @@ -11,5 +12,6 @@ export {
users,
settings,
commands,
search
search,
context
}
8 changes: 7 additions & 1 deletion src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<switch-button v-show="isListing"></switch-button>
<download-button v-show="showDownloadButton"></download-button>
<upload-button v-show="showUpload"></upload-button>
<bookmark-button v-show="showBookmarkButton"></bookmark-button>
<info-button v-show="isFiles"></info-button>

<button v-show="isListing" @click="openSelect" :aria-label="$t('buttons.selectMultiple')" :title="$t('buttons.selectMultiple')" class="action">
Expand All @@ -71,6 +72,7 @@ import MoveButton from './buttons/Move'
import CopyButton from './buttons/Copy'
import ShareButton from './buttons/Share'
import ShellButton from './buttons/Shell'
import BookmarkButton from './buttons/Bookmark'
import {mapGetters, mapState} from 'vuex'
import { logoURL } from '@/utils/constants'
import * as api from '@/api'
Expand All @@ -89,7 +91,8 @@ export default {
UploadButton,
SwitchButton,
MoveButton,
ShellButton
ShellButton,
BookmarkButton
},
data: function () {
return {
Expand Down Expand Up @@ -145,6 +148,9 @@ export default {
? (this.selectedCount === 1 && this.user.perm.rename)
: this.user.perm.rename)
},
showBookmarkButton () {
return this.isFiles && this.isListing
},
showShareButton () {
return this.isFiles && (this.isListing
? (this.selectedCount === 1 && this.user.perm.share)
Expand Down
19 changes: 17 additions & 2 deletions src/components/Sidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
<span>{{ $t('sidebar.myFiles') }}</span>
</router-link>

<div v-if="user.perm.create">
<div>
<router-link v-for="(bookmark) in bookmarks" :to="'/files'+bookmark.path" class="action" :aria-label="bookmark.name" :title="bookmark.name">
<i class="material-icons">folder</i>
<span>{{ bookmark.name }}</span>
</router-link>
</div>

<div v-if="user.perm.create" v-show="showNew">
<button @click="$store.commit('showHover', 'newDir')" class="action" :aria-label="$t('sidebar.newFolder')" :title="$t('sidebar.newFolder')">
<i class="material-icons">create_new_folder</i>
<span>{{ $t('sidebar.newFolder') }}</span>
Expand Down Expand Up @@ -62,10 +69,18 @@ export default {
name: 'sidebar',
computed: {
...mapState([ 'user' ]),
...mapGetters([ 'isLogged' ]),
...mapGetters([
'isLogged',
'bookmarks',
'isFiles',
'isListing'
]),
active () {
return this.$store.state.show === 'sidebar'
},
showNew() {
return this.isFiles && this.isListing
},
#: () => #,
version: () => version,
disableExternal: () => disableExternal,
Expand Down
43 changes: 43 additions & 0 deletions src/components/buttons/Bookmark.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<button @click="toggle" :aria-label="$t('buttons.bookmark')" :title="$t('buttons.bookmark')" class="action" id="bookmark-button">
<i class="material-icons">{{ icon }}</i>
<span>{{ $t('buttons.bookmark') }}</span>
</button>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import { files as filesApi, context as contextApi } from '@/api'

export default {
name: 'bookmark-button',
computed: {
...mapState(['req']),
icon: function () {
if (this.req.bookmarked) return 'bookmark'
return 'bookmark_border'
}
},
methods: {
...mapMutations([ 'updateBookmark', 'closeHovers' ]),
toggle: async function () {
this.closeHovers()

const data = {
path: this.req.path,
bookmarked: (this.icon === 'bookmark_border')
}

try {
await filesApi.bookmark([data])
this.updateBookmark(data)

const ctx = await contextApi.get()
this.$store.commit('updateContext', ctx)
} catch (e) {
this.$showError(e)
}
}
}
}
</script>
3 changes: 2 additions & 1 deletion src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"toggleSidebar": "Toggle sidebar",
"update": "Update",
"upload": "Upload",
"permalink": "Get Permanent Link"
"permalink": "Get Permanent Link",
"bookmark": "Bookmark"
},
"success": {
"linkCopied": "Link copied!"
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"toggleSidebar": "Afficher/Masquer la barre latérale",
"update": "Mettre à jour",
"upload": "Importer",
"permalink": "Obtenir un lien permanent"
"permalink": "Obtenir un lien permanent",
"bookmark": "Retenir dans les marques pages"
},
"success": {
"linkCopied": "Link copied!"
Expand Down
3 changes: 2 additions & 1 deletion src/store/getters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const getters = {
isFiles: state => !state.loading && state.route.name === 'Files',
isListing: (state, getters) => getters.isFiles && state.req.isDir,
isEditor: (state, getters) => getters.isFiles && (state.req.type === 'text' || state.req.type === 'textImmutable'),
selectedCount: state => state.selected.length
selectedCount: state => state.selected.length,
bookmarks: state => state.context.bookmarks
}

export default getters
1 change: 1 addition & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Vue.use(Vuex)
const state = {
user: null,
req: {},
context: {},
oldReq: {},
clipboard: {
key: '',
Expand Down
8 changes: 8 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ const mutations = {
state.user[field] = value[field]
}
},
updateBookmark: (state, value) => {
if (value.path == state.req.path) {
state.req.bookmarked = value.bookmarked
}
},
updateRequest: (state, value) => {
state.oldReq = state.req
state.req = value
},
updateContext: (state, value) => {
state.context = value
},
updateClipboard: (state, value) => {
state.clipboard.key = value.key
state.clipboard.items = value.items
Expand Down
9 changes: 9 additions & 0 deletions src/views/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Sidebar from '@/components/Sidebar'
import Prompts from '@/components/prompts/Prompts'
import SiteHeader from '@/components/Header'
import Shell from '@/components/Shell'
import { context as api } from '@/api'

export default {
name: 'layout',
Expand All @@ -38,6 +39,14 @@ export default {
this.$store.commit('multiple', false)
if (this.$store.state.show !== 'success') this.$store.commit('closeHovers')
}
},
async created() {
try {
const res = await api.get()
this.$store.commit('updateContext', res)
} catch (e) {
this.$showError(e)
}
}
}
</script>