Update settings page layout and style

next
neobooru 2022-02-01 23:41:36 +01:00
parent 2bd8f1520c
commit 27b8837210
1 changed files with 151 additions and 67 deletions

View File

@ -1,43 +1,57 @@
<template> <template>
<div class="settings-container"> <div class="content-holder">
<div class="settings-header"> <div class="content-wrapper">
<strong>SzuruChrome settings</strong> <strong>SzuruChrome Settings</strong>
</div>
<div class="settings-content"> <p>General settings which apply to all engines.</p>
<ul class="input">
<li class="full-width">
<label>Szurubooru URL</label><input text="Szurubooru URL" type="text" name="domain" v-model="domain" />
</li>
<li><label>Username</label><input text="Username" type="text" name="username" v-model="username" /></li>
<li>
<label>Authentication token</label
><input text="Authentication token" type="text" name="token" v-model="authToken" />
</li>
</ul>
<ul class="input">
<li>
<label> <label>
Szurubooru URL
<br />
<input type="text" name="domain" v-model="domain" />
</label>
<br />
<label>
Username
<br />
<input type="text" name="username" v-model="username" />
</label>
<label>
Authentication token
<br />
<input type="text" name="token" v-model="authToken" />
</label>
<br />
<label>
Automatically search for similar posts
<input type="checkbox" name="autoSearchSimilar" v-model="autoSearchSimilar" /> <input type="checkbox" name="autoSearchSimilar" v-model="autoSearchSimilar" />
Automatically search for similar posts
</label> </label>
<br /> <p class="hint">
Automatically start searching for similar posts when opening the popup. Enabling this option will hide the
"Find Similar" button.
</p>
</li>
<li>
<label> <label>
Use original image source when available
<input type="checkbox" name="useOriginalSource" v-model="useOriginalSource" /> <input type="checkbox" name="useOriginalSource" v-model="useOriginalSource" />
Use original image source when available
</label> </label>
<br /> <p class="hint">
Use the original image source when available. Usually this will mean a Twitter, DeviantArt, ArtStation, or
Pixiv page.
</p>
</li>
<li>
<label> <label>
Show how often a tag is used in the selected szurubooru instance
<input type="checkbox" name="loadTagCounts" v-model="loadTagCounts" /> <input type="checkbox" name="loadTagCounts" v-model="loadTagCounts" />
Show how often a tag is used in the selected szurubooru instance
</label> </label>
<br /> <p class="hint">
<div class="settings-footer-buttons"> Shows how often a given tag is used in the selected szurubooru instance. No number will be displayed when
the tag does not yet exist.
</p>
</li>
</ul>
<div class="settings-footer">
<span class="status" :class="statusType">{{ statusText }}</span>
<button @click="testConnection">Test connection</button> <button @click="testConnection">Test connection</button>
<button @click="saveSettings" class="primary">Save settings</button> <button @click="saveSettings" class="primary">Save settings</button>
</div> </div>
@ -50,6 +64,8 @@ import Vue from "vue";
import SzuruWrapper from "../SzuruWrapper"; import SzuruWrapper from "../SzuruWrapper";
import { Config, SzuruSiteConfig } from "../Config"; import { Config, SzuruSiteConfig } from "../Config";
type StatusType = "ok" | "error";
export default Vue.extend({ export default Vue.extend({
data() { data() {
return { return {
@ -59,12 +75,14 @@ export default Vue.extend({
autoSearchSimilar: false, autoSearchSimilar: false,
loadTagCounts: false, loadTagCounts: false,
useOriginalSource: false, useOriginalSource: false,
statusText: "",
statusType: "",
}; };
}, },
methods: { methods: {
async testConnection() { async testConnection() {
if (!this.domain || !this.username || !this.authToken) { if (!this.domain || !this.username || !this.authToken) {
alert("Domain, username and authentication token are all required."); this.setStatus("Domain, username and authentication token are all required.", "error");
return; return;
} }
@ -74,17 +92,18 @@ export default Vue.extend({
const instanceName = info?.config.name; const instanceName = info?.config.name;
if (instanceName == undefined) { if (instanceName == undefined) {
alert(`Connected to ${this.domain}, but it is not a szurubooru instance.`); this.setStatus(`Connected to ${this.domain}, but it is not a szurubooru instance.`, "error");
} else { } else {
alert(`Connected to ${info.config.name} at ${this.domain}`); this.setStatus(`Connected to ${info.config.name} at ${this.domain}`);
} }
} catch (ex) { } catch (ex) {
alert("Couldn't connect to " + this.domain + "\n\n" + ex); // TODO: This error message is not very descriptive.
console.dir(ex);
this.setStatus("Couldn't connect to " + this.domain + "\n\n" + ex, "error");
} }
}, },
async saveSettings() { async saveSettings() {
let config = await Config.load(); let config = await Config.load();
console.dir(config);
// We currently only support one domain // We currently only support one domain
let siteConfig = new SzuruSiteConfig(); let siteConfig = new SzuruSiteConfig();
@ -97,12 +116,18 @@ export default Vue.extend({
config.useOriginalSource = this.useOriginalSource; config.useOriginalSource = this.useOriginalSource;
await config.save(); await config.save();
this.setStatus("Settings successfully saved");
},
setStatus(text: string, type: StatusType = "ok") {
this.statusText = text;
this.statusType = "status-" + type;
}, },
}, },
async mounted() { async mounted() {
let config = await Config.load(); let config = await Config.load();
console.log(`Loaded ${config.sites.length} sites`); // console.log(`Loaded ${config.sites.length} sites`);
// We currently only support one domain // We currently only support one domain
if (config.sites.length > 0) { if (config.sites.length > 0) {
@ -119,31 +144,90 @@ export default Vue.extend({
</script> </script>
<style scoped> <style scoped>
label { .content-holder {
margin-bottom: 10px; padding: 1.5em;
display: flex;
justify-content: center;
} }
.settings-container { .content-holder > .content-wrapper {
margin: 0; box-sizing: border-box;
position: absolute; text-align: left;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
padding: 20px;
background-color: #f5f5f5;
}
.settings-header {
margin-bottom: 20px;
}
.settings-footer-buttons {
float: right;
}
.settings-content > label {
display: inline-block; display: inline-block;
flex: auto;
max-width: 1000px;
}
.content-holder > .content-wrapper:not(.transparent) {
background: #f5f5f5;
padding: 1.8em;
}
.settings-footer {
display: flex;
gap: 5px;
flex-wrap: wrap;
}
.settings-footer .status {
flex-grow: 1;
}
.settings-footer > span.status-ok {
color: green;
}
.settings-footer > span.status-error {
color: red;
}
.input {
list-style-type: none;
margin: 0 0 2em;
padding: 0;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.input li {
flex: 1 0 20em;
}
.input li.full-width {
min-width: 100%;
}
.input label {
display: block;
padding: 0.3em 0;
}
.hint {
margin-top: 0.2em;
margin-bottom: 0;
color: #888;
font-size: 80%;
line-height: 120%;
}
input[type="email"],
input[type="number"],
input[type="password"],
input[type="text"],
select,
textarea {
vertical-align: top;
font-family: "Droid Sans", sans-serif;
font-size: 100%;
padding: 0.2em 0.3em;
text-overflow: ellipsis;
width: 100%;
box-sizing: border-box;
border: 2px solid #eee;
background: #fafafa;
color: #111;
box-shadow: none;
transition: border-color 0.1s linear, background-color 0.1s linear;
} }
</style> </style>