From 071d4ce795c029632e90cdcebe288a4172f7af96 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Wed, 13 Sep 2023 20:43:56 +0200 Subject: [PATCH] install --- public/js/components/pages/cdb/Detail.js | 9 ++--- public/js/components/pages/cdb/Install.js | 45 +++++++++++++++++------ public/js/components/pages/mods/Mods.js | 32 ++++++++++------ public/js/service/mods.js | 17 ++++++++- public/js/store/mods.js | 7 ---- 5 files changed, 73 insertions(+), 37 deletions(-) delete mode 100644 public/js/store/mods.js diff --git a/public/js/components/pages/cdb/Detail.js b/public/js/components/pages/cdb/Detail.js index 28a7ae61..6c44595b 100644 --- a/public/js/components/pages/cdb/Detail.js +++ b/public/js/components/pages/cdb/Detail.js @@ -1,6 +1,5 @@ - import { get_dependencies, get_package } from "../../../service/cdb.js"; -import store from '../../../store/mods.js'; +import { get_cdb_mod, get_game } from "../../../service/mods.js"; import FeedbackButton from "../../FeedbackButton.js"; import DefaultLayout from "../../layouts/DefaultLayout.js"; import { START, ADMINISTRATION, MODS, CDB, CDB_DETAIL } from "../../Breadcrumb.js"; @@ -32,8 +31,8 @@ export default { cdb_link: function() { return `https://content.minetest.net/packages/${this.pkg.author}/${this.pkg.name}/`; }, - is_installed: function() { - return store.list && store.list.find(m => m.name == this.name && m.author == this.author); + install_disabled: function() { + return get_cdb_mod(this.author, this.name) || (this.pkg && this.pkg.type == "game" && get_game()); } }, template: /*html*/` @@ -82,7 +81,7 @@ export default { View source
- + Install diff --git a/public/js/components/pages/cdb/Install.js b/public/js/components/pages/cdb/Install.js index ee9e0d3c..46962b31 100644 --- a/public/js/components/pages/cdb/Install.js +++ b/public/js/components/pages/cdb/Install.js @@ -1,6 +1,6 @@ import DefaultLayout from "../../layouts/DefaultLayout.js"; -import { add } from "../../../service/mods.js"; -import { resolve_package } from "../../../api/cdb.js"; +import { add, get_cdb_mod } from "../../../service/mods.js"; +import { resolve_package, get_package } from "../../../api/cdb.js"; import { validate } from "../../../api/mods.js"; import { START, ADMINISTRATION, MODS, CDB, CDB_DETAIL } from "../../Breadcrumb.js"; import CDBPackageLink from "../../CDBPackageLink.js"; @@ -12,10 +12,10 @@ const DependencyInstallRow = { return this.dep.choices.length == 0 && !this.dep.installed; }, is_installed: function(){ - return this.dep.choices.length == 0 && this.dep.installed; + return this.dep.installed; }, has_choices: function() { - return this.dep.choices.length > 0; + return this.dep.choices.length > 0 && !this.dep.installed; } }, template: /*html*/` @@ -51,6 +51,7 @@ export default { missing_dep: false, selected_package_map: {}, // modname -> packagename installed_mods: [], + pkg: null, deps: [], breadcrumb: [START, ADMINISTRATION, MODS, CDB, CDB_DETAIL(this.author, this.name), { name: `Install`, @@ -60,9 +61,18 @@ export default { }; }, created: function() { - validate() - .then(r => this.installed_mods = r.installed) - .then(() => this.fetch_dependencies()); + get_package(this.author, this.name) + .then(pkg => { + const mod = get_cdb_mod(pkg.author, pkg.name); + pkg.installed = !!mod; + if (pkg.type == "mod") { + // resolve mod dependencies + validate() + .then(r => this.installed_mods = r.installed) + .then(() => this.fetch_dependencies()); + } + this.pkg = pkg; + }); }, methods: { fetch_dependencies: function() { @@ -93,9 +103,21 @@ export default { }, install_next: function() { const next_dep = this.deps.find(d => !d.installed); + if (!next_dep && !this.pkg.installed) { + // install root dep + add({ + author: this.pkg.author, + name: this.pkg.name, + mod_type: this.pkg.type, + source_type: "cdb" + }) + .then(() => this.pkg.installed = true); + } + if (!next_dep) { return; } + const parts = next_dep.selected.split("/"); add({ @@ -125,16 +147,15 @@ export default { Provided by package - - + + {{name}} + - - - +
diff --git a/public/js/components/pages/mods/Mods.js b/public/js/components/pages/mods/Mods.js index 28e2af59..b4f14e7f 100644 --- a/public/js/components/pages/mods/Mods.js +++ b/public/js/components/pages/mods/Mods.js @@ -1,13 +1,14 @@ -import store from '../../../store/mods.js'; -import { add, remove } from '../../../service/mods.js'; +import { add, remove, get_all, is_busy, get_git_mod } from '../../../service/mods.js'; import FeedbackButton from '../../FeedbackButton.js'; import DefaultLayout from '../../layouts/DefaultLayout.js'; +import CDBPackageLink from '../../CDBPackageLink.js'; import { START, ADMINISTRATION, MODS } from '../../Breadcrumb.js'; export default { components: { "feedback-button": FeedbackButton, - "default-layout": DefaultLayout + "default-layout": DefaultLayout, + "cdb-package-link": CDBPackageLink }, data: () => { return { @@ -16,7 +17,6 @@ export default { add_source_type: "git", add_url: "", add_version: "", - store: store, breadcrumb: [START, ADMINISTRATION, MODS] }; }, @@ -45,21 +45,26 @@ export default { branch: "refs/heads/master" }); }, - remove: remove + remove: remove, + get_mods: get_all, + get_git_mod: get_git_mod + }, + computed: { + busy: is_busy }, template: /*html*/`

Mod management - +

-
+
Warning: The mtui mod is not installed, some features may not work properly - @@ -124,17 +129,20 @@ export default { - + Add from ContentDB - + {{mod.mod_type}} - {{mod.name}} + + + {{mod.name}} + @@ -165,7 +173,7 @@ export default { Edit - + Remove
diff --git a/public/js/service/mods.js b/public/js/service/mods.js index bbf184a1..5453d2aa 100644 --- a/public/js/service/mods.js +++ b/public/js/service/mods.js @@ -1,6 +1,11 @@ import { list_mods, create_mod, remove_mod } from '../api/mods.js'; -import store from '../store/mods.js'; +const store = Vue.reactive({ + list: [], + busy: false, + has_mtui_mod: false, + error_msg: "" +}); export const update = () => { store.busy = true; @@ -10,6 +15,16 @@ export const update = () => { .finally(() => store.busy = false); }; +export const is_busy = () => store.busy; + export const add = m => create_mod(m).then(update); export const remove = id => remove_mod(id).then(update); + +export const get_all = () => store.list; + +export const get_cdb_mod = (author, name) => store.list.find(m => m.name == name && m.author == author); + +export const get_git_mod = name => store.list.find(m => m.name == name); + +export const get_game = () => store.list.find(m => m.mod_type == "game"); \ No newline at end of file diff --git a/public/js/store/mods.js b/public/js/store/mods.js deleted file mode 100644 index ca28fd5d..00000000 --- a/public/js/store/mods.js +++ /dev/null @@ -1,7 +0,0 @@ - -export default Vue.reactive({ - list: null, - busy: false, - has_mtui_mod: false, - error_msg: "" -}); \ No newline at end of file