memories/src/components/FirstStart.vue

189 lines
4.2 KiB
Vue
Raw Normal View History

2022-10-25 04:30:43 +00:00
<template>
2022-10-28 19:08:34 +00:00
<NcContent app-name="memories">
<NcAppContent>
<div class="outer fill-block" :class="{ show }">
<div class="title">
<img :src="banner" />
</div>
<div class="text">
{{ t("memories", "A better photos experience awaits you") }} <br />
{{
t("memories", "Choose the root folder of your timeline to begin")
}}
</div>
<div class="admin-text" v-if="isAdmin">
{{ t("memories", "If you just installed Memories, run:") }}
<br />
<code>occ memories:index</code>
</div>
<div class="error" v-if="error">
{{ error }}
</div>
<div class="info" v-if="info">
{{ info }} <br />
<NcButton @click="finish" class="button" type="primary">
{{ t("memories", "Continue to Memories") }}
</NcButton>
</div>
<NcButton @click="begin" class="button" v-if="info">
{{ t("memories", "Choose again") }}
</NcButton>
<NcButton @click="begin" class="button" type="primary" v-else>
{{ t("memories", "Click here to start") }}
</NcButton>
<div class="footer">
{{ t("memories", "You can always change this later in settings") }}
</div>
</div>
</NcAppContent>
</NcContent>
2022-10-25 04:30:43 +00:00
</template>
<script lang="ts">
2022-10-28 19:08:34 +00:00
import { Component, Mixins } from "vue-property-decorator";
import { NcContent, NcAppContent, NcButton } from "@nextcloud/vue";
import { getFilePickerBuilder } from "@nextcloud/dialogs";
import { generateUrl } from "@nextcloud/router";
import { getCurrentUser } from "@nextcloud/auth";
import axios from "@nextcloud/axios";
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
import GlobalMixin from "../mixins/GlobalMixin";
import UserConfig from "../mixins/UserConfig";
2022-10-25 04:30:43 +00:00
import banner from "../assets/banner.svg";
2022-10-28 19:08:34 +00:00
import { IDay } from "../types";
2022-10-25 04:30:43 +00:00
@Component({
2022-10-28 19:08:34 +00:00
components: {
NcContent,
NcAppContent,
NcButton,
},
2022-10-25 04:30:43 +00:00
})
export default class FirstStart extends Mixins(GlobalMixin, UserConfig) {
2022-10-28 19:08:34 +00:00
banner = banner;
error = "";
info = "";
show = false;
chosenPath = "";
mounted() {
window.setTimeout(() => {
this.show = true;
}, 300);
}
get isAdmin() {
return getCurrentUser().isAdmin;
}
async begin() {
const path = await this.chooseFolder(
this.t("memories", "Choose the root of your timeline"),
"/"
);
// Get folder days
this.error = "";
this.info = "";
const query = new URLSearchParams();
query.set("timelinePath", path);
let url = generateUrl("/apps/memories/api/days?" + query.toString());
const res = await axios.get<IDay[]>(url);
// Check response
if (res.status !== 200) {
this.error = this.t(
"memories",
"The selected folder does not seem to be valid. Try again."
);
return;
2022-10-25 04:30:43 +00:00
}
2022-10-28 19:08:34 +00:00
// Count total photos
const total = res.data.reduce((acc, day) => acc + day.count, 0);
this.info = this.t("memories", "Found {total} photos in {path}", {
total,
path,
});
this.chosenPath = path;
}
async finish() {
this.show = false;
await new Promise((resolve) => setTimeout(resolve, 500));
this.config_timelinePath = this.chosenPath;
await this.updateSetting("timelinePath");
}
async chooseFolder(title: string, initial: string) {
const picker = getFilePickerBuilder(title)
.setMultiSelect(false)
.setModal(true)
.setType(1)
.addMimeTypeFilter("httpd/unix-directory")
.allowDirectories()
.startAt(initial)
.build();
return await picker.pick();
}
2022-10-25 04:30:43 +00:00
}
</script>
<style lang="scss" scoped>
.outer {
2022-10-28 19:08:34 +00:00
padding: 20px;
text-align: center;
transition: opacity 1s ease;
opacity: 0;
&.show {
opacity: 1;
}
.title {
font-size: 2.8em;
line-height: 1.1em;
font-family: cursive;
font-weight: 500;
margin-top: 10px;
margin-bottom: 20px;
width: 100%;
filter: var(--background-invert-if-dark);
> img {
max-width: calc(100vw - 40px);
2022-10-25 04:30:43 +00:00
}
2022-10-28 19:08:34 +00:00
}
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
.admin-text {
margin-top: 10px;
}
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
.error {
color: red;
}
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
.info {
margin-top: 10px;
font-weight: bold;
}
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
.button {
display: inline-block;
margin: 15px;
}
2022-10-25 04:30:43 +00:00
2022-10-28 19:08:34 +00:00
.footer {
font-size: 0.8em;
}
2022-10-25 04:30:43 +00:00
}
</style>