bookmarks/src/components/Settings.vue

230 lines
6.0 KiB
Vue
Raw Normal View History

2019-08-20 12:45:43 +00:00
<template>
<div class="settings">
<input type="file"
class="import"
size="5"
@change="onImportSubmit">
<button @click="onImportOpen">
2020-04-17 11:22:00 +00:00
<span :class="{'icon-upload': !importing, 'icon-loading-small': importing}" />{{ t('bookmarks', 'Import') }}
</button>
<button @click="onExport">
<span class="icon-download" /> {{ t('bookmarks', 'Export') }}
</button>
2019-08-20 12:45:43 +00:00
<label><h3>{{ t('bookmarks', 'Sorting') }}</h3>
<select :value="sorting" @change="onChangeSorting">
<option id="added" value="added">
{{ t('bookmarks', 'Recently added') }}
</option>
<option id="title" value="title">
{{ t('bookmarks', 'Alphabetically') }}
</option>
<option id="clickcount" value="clickcount">
{{ t('bookmarks', 'Most visited') }}
</option>
<option id="lastmodified" value="lastmodified">
{{ t('bookmarks', 'Last modified') }}
</option>
<option id="index" value="index">
{{ t('bookmarks', 'Custom order') }}
</option>
</select>
</label>
2019-08-20 12:45:43 +00:00
<label><h3>{{ t('bookmarks', 'Archive path') }}</h3>
<p>{{ t('bookmarks',
'Enter the path of a folder where bookmarked files should be stored'
) }}</p>
<input
:value="archivePath"
:readonly="true"
@click="onChangeArchivePath">
</label>
<h3>{{ t('bookmarks', 'Client apps') }}</h3>
<p>
{{
t('bookmarks',
'Also check out the collection of client apps that integrate with this app: '
)
}}
<a href="https://github.com/nextcloud/bookmarks#third-party-clients">{{
t('bookmarks', 'Client apps')
}}</a>
</p>
<label>
<h3>{{ t('bookmarks', 'Install web app') }}</h3>
<a class="button" href="#" @click.prevent="clickAddToHomeScreen">{{ t('bookmarks', 'Install on home screen') }}</a>
</label>
2019-08-28 12:49:51 +00:00
<label><h3>{{ t('bookmarks', 'Bookmarklet') }}</h3>
<p>{{ t('bookmarks',
'Drag this to your browser bookmarks and click it to quickly bookmark a webpage'
) }}</p>
<a
class="button"
:href="bookmarklet"
@click.prevent="void 0">{{
t('bookmarks', 'Add to {instanceName}', {
instanceName: oc_defaults.name
})
}}</a>
</label>
2019-08-20 12:45:43 +00:00
<label><h3>{{ t('bookmarks', 'Clear data') }}</h3>
<p>{{
t('bookmarks',
'Permanently remove all bookmarks from your account.'
)
}}</p>
<button
class="clear-data"
@click="onClearData">
<span :class="{'icon-delete': !deleting, 'icon-loading-small': deleting}" />
{{ t('bookmarks', 'Delete all bookmarks') }}
</button>
</label>
</div>
2019-08-20 12:45:43 +00:00
</template>
<script>
import { generateUrl } from '@nextcloud/router'
import { actions } from '../store/'
import { getRequestToken } from '@nextcloud/auth'
import { getFilePickerBuilder } from '@nextcloud/dialogs'
2020-03-25 12:19:17 +00:00
export default {
name: 'Settings',
components: {},
2020-04-17 11:22:00 +00:00
data() {
return {
importing: false,
deleting: false,
addToHomeScreen: null,
filePicker: getFilePickerBuilder(this.t('bookmarks', 'Archive path'))
.allowDirectories(true)
.setModal(true)
.setType(1)// CHOOSE
.setMultiSelect(false)
.build(),
2020-04-17 11:22:00 +00:00
}
},
computed: {
oc_defaults() {
return window.oc_defaults
},
bookmarklet() {
const bookmarkletUrl
2020-03-25 12:19:17 +00:00
= window.location.origin + generateUrl('/apps/bookmarks/bookmarklet')
return `javascript:(function(){var a=window,b=document,c=encodeURIComponent,e=c(document.title),d=a.open('${bookmarkletUrl}?url='+c(b.location)+'&title='+e,'bkmk_popup','left='+((a.screenX||a.screenLeft)+10)+',top='+((a.screenY||a.screenTop)+10)+',height=500px,width=550px,resizable=1,alwaysRaised=1');a.setTimeout(function(){d.focus()},300);})();`
2019-08-20 12:45:43 +00:00
},
viewMode() {
return this.$store.state.settings.viewMode
2019-08-20 12:45:43 +00:00
},
sorting() {
return this.$store.state.settings.sorting
},
archivePath() {
return this.$store.state.settings.archivePath
},
2019-08-20 12:45:43 +00:00
},
mounted() {
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault()
// Stash the event so it can be triggered later.
this.addToHomeScreen = e
this.showAddToHomeScreen = true
})
},
2019-08-20 12:45:43 +00:00
methods: {
onImportOpen(e) {
e.target.previousElementSibling.click()
2019-08-20 12:45:43 +00:00
},
2020-04-17 11:22:00 +00:00
async onImportSubmit(e) {
this.importing = true
try {
2020-08-27 16:24:55 +00:00
await this.$store.dispatch(actions.IMPORT_BOOKMARKS, { file: e.target.files[0], folder: this.$route.params.folder || -1 })
2020-05-20 12:51:39 +00:00
} catch (e) {
console.warn(e)
2020-04-17 11:22:00 +00:00
}
2020-05-20 12:51:39 +00:00
this.importing = false
2019-08-20 12:45:43 +00:00
},
onExport() {
2019-08-26 12:29:07 +00:00
window.location
= 'bookmark/export?requesttoken='
2020-03-25 12:19:17 +00:00
+ encodeURIComponent(getRequestToken())
2019-08-20 12:45:43 +00:00
},
async onChangeSorting(e) {
await this.$store.dispatch(actions.SET_SETTING, {
key: 'sorting',
value: e.target.value,
})
2019-10-12 18:00:15 +00:00
await this.$store.dispatch(actions.FETCH_PAGE)
2019-08-20 12:45:43 +00:00
},
async onChangeArchivePath(e) {
const path = await this.filePicker.pick()
await this.$store.dispatch(actions.SET_SETTING, {
key: 'archivePath',
value: path,
})
},
2019-08-20 12:45:43 +00:00
async onClearData() {
if (
!confirm(
t('bookmarks', 'Do you really want to delete all your bookmarks?')
)
) {
return
2019-08-20 12:45:43 +00:00
}
this.deleting = true
await this.$store.dispatch(actions.DELETE_BOOKMARKS)
2020-04-17 11:22:00 +00:00
await this.$router.push({ name: this.routes.HOME })
this.deleting = false
},
clickAddToHomeScreen() {
if (!this.addToHomeScreen) {
alert(this.t('bookmarks', 'Please select "Add to home screen" in your browser menu'))
return
}
// Show the prompt
this.addToHomeScreen.prompt()
// Wait for the user to respond to the prompt
this.addToHomeScreen.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.warn('User accepted the A2HS prompt')
} else {
console.warn('User dismissed the A2HS prompt')
}
this.addToHomeScreen = null
})
},
},
}
2019-08-20 12:45:43 +00:00
</script>
<style>
.import {
opacity: 0;
position: absolute;
2019-08-26 22:38:02 +00:00
top: 0;
left: -1000px;
2019-08-20 12:45:43 +00:00
}
2019-08-26 22:38:02 +00:00
2019-08-28 12:49:51 +00:00
.settings label,
.settings input,
.settings select,
2020-08-25 15:18:36 +00:00
.settings button,
2019-08-28 12:49:51 +00:00
.settings label a.button {
2019-08-29 09:23:35 +00:00
display: block;
2020-08-25 15:18:36 +00:00
width: 100%;
2019-08-28 12:49:51 +00:00
}
.settings label {
2019-08-29 09:23:35 +00:00
margin-top: 10px;
2019-08-28 12:49:51 +00:00
}
2019-08-26 12:57:02 +00:00
.settings a:link:not(.button) {
2019-08-25 12:24:46 +00:00
text-decoration: underline;
}
2019-08-20 12:45:43 +00:00
</style>