added admin option for configuring Aria2 globally;option for diallowing aria2 settings for non-privileged users;cleanining up
This commit is contained in:
@@ -10,6 +10,15 @@
|
||||
:path="option.path"
|
||||
/>
|
||||
</div>
|
||||
<div class="section">
|
||||
<toggleButton
|
||||
:defaultStatus="pStatus"
|
||||
disabledText="No Aria2 Settings for non-admin Users"
|
||||
enabledText="No Aria2 Settings for non-admin Users"
|
||||
@changed="toggle"
|
||||
name="disallow_aria2_settings"
|
||||
></toggleButton>
|
||||
</div>
|
||||
<customOptions
|
||||
name="admin-aria2-settings"
|
||||
@mounted="render"
|
||||
@@ -25,6 +34,7 @@ import customOptions from "./components/customOptions";
|
||||
import helper from "./utils/helper";
|
||||
import aria2Options from "./utils/aria2Options";
|
||||
import settingsRow from "./components/settingsRow";
|
||||
import toggleButton from "./components/toggleButton";
|
||||
|
||||
export default {
|
||||
name: "adminSettings",
|
||||
@@ -32,13 +42,31 @@ export default {
|
||||
return {
|
||||
options: [],
|
||||
validOptions: aria2Options,
|
||||
settings: [],
|
||||
pStatus: false,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
customOptions,
|
||||
settingsRow,
|
||||
toggleButton,
|
||||
},
|
||||
methods: {
|
||||
toggle(name, value) {
|
||||
let data = {};
|
||||
data[name] = value ? 1 : 0;
|
||||
let path = "/apps/ncdownloader/admin/save";
|
||||
const url = helper.generateUrl(path);
|
||||
helper
|
||||
.httpClient(url)
|
||||
.setData(data)
|
||||
.setHandler((resp) => {
|
||||
if (resp["message"]) {
|
||||
helper.message(helper.t(resp["message"]), 1000);
|
||||
}
|
||||
})
|
||||
.send();
|
||||
},
|
||||
render(event, $vm) {
|
||||
helper
|
||||
.httpClient(helper.generateUrl("/apps/ncdownloader/admin/aria2/get"))
|
||||
@@ -67,6 +95,8 @@ export default {
|
||||
try {
|
||||
let data = this.$el.parentElement.getAttribute("data-settings");
|
||||
data = JSON.parse(data);
|
||||
this.settings = data;
|
||||
this.pStatus = helper.str2Boolean(data["disallow_aria2_settings"]);
|
||||
let path = "/apps/ncdownloader/admin/save";
|
||||
this.options = [
|
||||
{
|
||||
@@ -87,7 +117,9 @@ export default {
|
||||
label: "Aria2 RPC Token",
|
||||
id: "ncd_aria2_rpc_token",
|
||||
value: data.ncd_aria2_rpc_token,
|
||||
placeholder: data.ncd_aria2_rpc_token ? data.ncd_aria2_rpc_token : "ncdownloader123",
|
||||
placeholder: data.ncd_aria2_rpc_token
|
||||
? data.ncd_aria2_rpc_token
|
||||
: "ncdownloader123",
|
||||
path: path,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</button>
|
||||
<button
|
||||
class="custom-settings-save-btn"
|
||||
@click.prevent="saveOptions($event)"
|
||||
@click.prevent="saveOptions"
|
||||
:data-rel="id"
|
||||
>
|
||||
<slot name="save">Save</slot>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
placeholder="Leave empty if no value needed"
|
||||
class="form-input-text"
|
||||
/>
|
||||
<button class="has-content icon-close" @click="remove($event)"></button>
|
||||
<button class="has-content icon-close" @click="remove"></button>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
:name="id"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@blur="saveHandler($event)"
|
||||
@change="saveHandler"
|
||||
:data-rel="container"
|
||||
/>
|
||||
<input
|
||||
@@ -16,7 +16,7 @@
|
||||
type="button"
|
||||
value="save"
|
||||
:data-rel="container"
|
||||
@click.prevent="saveHandler($event)"
|
||||
@click.prevent="saveHandler"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -36,14 +36,15 @@ export default {
|
||||
},
|
||||
},
|
||||
data() {
|
||||
let id = this.id.replaceAll("_", "-");
|
||||
return {
|
||||
classes: this.id.replace("_", "-") + "-input",
|
||||
container: this.id.replace("_", "-") + "-container",
|
||||
classes: id + "-input",
|
||||
container: id + "-container",
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
saveHandler(e) {
|
||||
if (e.type == "blur" && this.useBtn) {
|
||||
if (e.type == "change" && this.useBtn) {
|
||||
return;
|
||||
}
|
||||
e.stopPropagation();
|
||||
@@ -56,6 +57,9 @@ export default {
|
||||
.httpClient(url)
|
||||
.setData(data)
|
||||
.setHandler(function (resp) {
|
||||
if (!resp) {
|
||||
return;
|
||||
}
|
||||
if (resp.error) {
|
||||
helper.error(resp.error);
|
||||
return;
|
||||
|
||||
@@ -36,10 +36,12 @@ class settingsForm {
|
||||
let items: dataItems = {
|
||||
id: keyId,
|
||||
name: '',
|
||||
value: ''
|
||||
value: '',
|
||||
placeholder: ""
|
||||
}
|
||||
div.appendChild(this._createInput(items));
|
||||
items.id = valueId
|
||||
items.placeholder = 'Leave empty if no value needed'
|
||||
div.appendChild(this._createInput(items));
|
||||
div.appendChild(this._createCancelBtn());
|
||||
return div;
|
||||
@@ -47,7 +49,7 @@ class settingsForm {
|
||||
|
||||
_createContainer(id: string): HTMLElement {
|
||||
let div = document.createElement("div");
|
||||
div.setAttribute("id",id);
|
||||
div.setAttribute("id", id);
|
||||
div.classList.add("autocomplete-container")
|
||||
return div;
|
||||
}
|
||||
@@ -81,7 +83,7 @@ class settingsForm {
|
||||
_createInput(data: dataItems): HTMLElement {
|
||||
let input = document.createElement('input');
|
||||
let type = data.type || "text";
|
||||
let placeholder = data.placeholder || 'Leave empty if no value needed';
|
||||
let placeholder = data.placeholder;
|
||||
let value = data.value || '';
|
||||
input.setAttribute('type', type);
|
||||
input.setAttribute('id', data.id);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
/>
|
||||
</div>
|
||||
<customOptions
|
||||
v-if="!disallowAria2Settings"
|
||||
name="custom-aria2-settings"
|
||||
title="Personal Aria2 Settings"
|
||||
@mounted="renderAria2"
|
||||
@@ -45,6 +46,7 @@ export default {
|
||||
options: [],
|
||||
aria2Options: aria2Options,
|
||||
ytdlOptions: ytdlOptions,
|
||||
disallowAria2Settings: false,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
@@ -99,6 +101,7 @@ export default {
|
||||
let data = this.$el.parentElement.getAttribute("data-settings");
|
||||
data = JSON.parse(data);
|
||||
let path = "/apps/ncdownloader/personal/save";
|
||||
this.disallowAria2Settings = helper.str2Boolean(data["disallow_aria2_settings"]);
|
||||
this.options = [
|
||||
{
|
||||
label: "Downloads Folder ",
|
||||
|
||||
@@ -356,6 +356,9 @@ const helper = {
|
||||
}
|
||||
}
|
||||
return data
|
||||
},
|
||||
isEmptyObject(obj) {
|
||||
return Object.keys(obj).length === 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user