mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-07-03 10:00:41 +00:00
fixed bugs, added data attr
This commit is contained in:
parent
a3d5c1ba9d
commit
65a0e389fa
3 changed files with 29 additions and 13 deletions
|
|
@ -10,13 +10,12 @@
|
||||||
/>
|
/>
|
||||||
<div class="button" @click="saveButton">
|
<div class="button" @click="saveButton">
|
||||||
<div class="material-icons">save</div>
|
<div class="material-icons">save</div>
|
||||||
Save
|
Save & Apply
|
||||||
</div>
|
</div>
|
||||||
<div class="button" @click="closeButton">
|
<div class="button" @click="closeButton">
|
||||||
<div class="material-icons">clear</div>
|
<div class="material-icons">clear</div>
|
||||||
Close
|
Close
|
||||||
</div>
|
</div>
|
||||||
<div class="button end" @click="applyButton">Apply</div>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- <prism-editor class="editor" v-model="code" language="css"></prism-editor> -->
|
<!-- <prism-editor class="editor" v-model="code" language="css"></prism-editor> -->
|
||||||
<codemirror
|
<codemirror
|
||||||
|
|
@ -97,6 +96,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
saving: false,
|
||||||
selectedThemeID: null,
|
selectedThemeID: null,
|
||||||
themes: null,
|
themes: null,
|
||||||
editing: null,
|
editing: null,
|
||||||
|
|
@ -143,30 +143,37 @@ export default {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
async saveButton() {
|
async saveButton() {
|
||||||
|
if (this.saving) {return}
|
||||||
|
this.saving = true;
|
||||||
const css = this.code;
|
const css = this.code;
|
||||||
const name = this.name;
|
const name = this.name;
|
||||||
if (typeof this.editing === 'string'){
|
if (typeof this.editing === 'string'){
|
||||||
const response = await ThemeService.update({ name, css }, this.editing);
|
const response = await ThemeService.update({ name, css }, this.editing);
|
||||||
|
this.applyButton(this.editing)
|
||||||
} else {
|
} else {
|
||||||
const response = await ThemeService.save({ name, css });
|
const response = await ThemeService.save({ name, css });
|
||||||
|
this.editing = response.result.data.id;
|
||||||
|
this.applyButton(response.result.data.id)
|
||||||
}
|
}
|
||||||
|
this.saving = false;
|
||||||
},
|
},
|
||||||
async applyButton(id) {
|
async applyButton(id) {
|
||||||
if (id) {
|
const {ok, result, error} = await ThemeService.getTheme(id);
|
||||||
const {ok, result, error} = await ThemeService.getTheme(id);
|
if (ok) {
|
||||||
if (ok) {
|
this.code = result.data.css;
|
||||||
this.code = result.data.css;
|
|
||||||
}
|
|
||||||
// save to local storage.
|
|
||||||
localStorage.setItem('appliedThemeId', id);
|
|
||||||
}
|
}
|
||||||
|
// save to local storage.
|
||||||
|
localStorage.setItem('appliedThemeId', id);
|
||||||
|
|
||||||
|
const styleEl = document.createElement("style");
|
||||||
|
styleEl.classList.add('theme-' + id);
|
||||||
|
styleEl.id = "theme";
|
||||||
|
styleEl.innerHTML = this.code;
|
||||||
|
|
||||||
const currentStyle = document.getElementById("theme");
|
const currentStyle = document.getElementById("theme");
|
||||||
if (currentStyle) {
|
if (currentStyle) {
|
||||||
currentStyle.innerHTML = this.code;
|
currentStyle.outerHTML = styleEl.outerHTML;
|
||||||
} else {
|
} else {
|
||||||
const styleEl = document.createElement("style");
|
|
||||||
styleEl.id = "theme";
|
|
||||||
styleEl.innerHTML = this.code;
|
|
||||||
document.head.innerHTML += styleEl.outerHTML;
|
document.head.innerHTML += styleEl.outerHTML;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -181,6 +188,11 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async deleteButton (id) {
|
async deleteButton (id) {
|
||||||
|
localStorage.removeItem('appliedThemeId');
|
||||||
|
const themeEl = document.getElementById('theme');
|
||||||
|
if (themeEl && themeEl.classList.contains('theme-' + id)) {
|
||||||
|
document.getElementById('theme').outerHTML = ''
|
||||||
|
}
|
||||||
const {ok, result, error} = await ThemeService.delete(id);
|
const {ok, result, error} = await ThemeService.delete(id);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
this.themes = this.themes.filter(t => t.id !== id);
|
this.themes = this.themes.filter(t => t.id !== id);
|
||||||
|
|
@ -242,6 +254,8 @@ export default {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
.editor {
|
.editor {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
.notice {
|
.notice {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div
|
||||||
class="server"
|
class="server"
|
||||||
|
:data-servername="serverData.name"
|
||||||
:class="{selected: selectedServerID === serverData.server_id, notifyAnimation: notification }"
|
:class="{selected: selectedServerID === serverData.server_id, notifyAnimation: notification }"
|
||||||
@contextmenu.prevent="contextEvent"
|
@contextmenu.prevent="contextEvent"
|
||||||
@mouseenter="hoverEvent"
|
@mouseenter="hoverEvent"
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ export default {
|
||||||
if (!ok) { return; }
|
if (!ok) { return; }
|
||||||
const styleEl = document.createElement('style');
|
const styleEl = document.createElement('style');
|
||||||
styleEl.id = "theme"
|
styleEl.id = "theme"
|
||||||
|
styleEl.classList.add('theme-' + result.data.id)
|
||||||
styleEl.innerHTML = result.data.css
|
styleEl.innerHTML = result.data.css
|
||||||
document.head.innerHTML += styleEl.outerHTML;
|
document.head.innerHTML += styleEl.outerHTML;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue