Skip to content

Commit

Permalink
install
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Sep 13, 2023
1 parent 5b73f15 commit 071d4ce
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 37 deletions.
9 changes: 4 additions & 5 deletions public/js/components/pages/cdb/Detail.js
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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*/`
Expand Down Expand Up @@ -82,7 +81,7 @@ export default {
View source
</a>
<hr>
<router-link class="btn btn-success" :to="'/cdb/install/' + pkg.author + '/' + pkg.name" :disabled="is_installed">
<router-link class="btn btn-success" :to="'/cdb/install/' + pkg.author + '/' + pkg.name" v-if="!install_disabled">
<i class="fa-solid fa-plus"></i>
Install
</router-link>
Expand Down
45 changes: 33 additions & 12 deletions public/js/components/pages/cdb/Install.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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*/`
Expand Down Expand Up @@ -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`,
Expand All @@ -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() {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -125,16 +147,15 @@ export default {
<th>Provided by package</th>
</tr>
</thead>
<tbody v-if="author">
<tr>
<tbody>
<tr v-if="pkg">
<td>{{name}}</td>
<td>
<cdb-package-link :author="author" :name="name"/>
<i class="fa fa-check" v-if="pkg.installed"></i>
</td>
</tr>
</tbody>
<tbody v-for="dep in deps">
<dependency-install-row :dep="dep" :selected_dep="dep.selected" v-on:select_dep="select_dep"/>
<dependency-install-row v-for="dep in deps" :dep="dep" :key="dep.name" :selected_dep="dep.selected" v-on:select_dep="select_dep"/>
</tbody>
</table>
<div class="row">
Expand Down
32 changes: 20 additions & 12 deletions public/js/components/pages/mods/Mods.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -16,7 +17,6 @@ export default {
add_source_type: "git",
add_url: "",
add_version: "",
store: store,
breadcrumb: [START, ADMINISTRATION, MODS]
};
},
Expand Down Expand Up @@ -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*/`
<default-layout icon="cubes" title="Mods" :breadcrumb="breadcrumb">
<h4>
Mod management
<i class="fa-solid fa-spinner fa-spin" v-if="store.busy"></i>
<i class="fa-solid fa-spinner fa-spin" v-if="busy"></i>
</h4>
<div class="alert alert-warning" v-if="store.list && !store.has_mtui_mod">
<div class="alert alert-warning" v-if="!get_git_mod('mtui')">
<div class="row">
<div class="col-12">
<i class="fa-solid fa-triangle-exclamation"></i>
<b>Warning:</b>
The <i>mtui</i> mod is not installed, some features may not work properly
<button class="btn btn-primary float-end" :disabled="store.busy" v-on:click="add_mtui_mod">
<button class="btn btn-primary float-end" :disabled="busy" v-on:click="add_mtui_mod">
<i class="fa fa-plus"></i>
Install "mtui" mod
</button>
Expand Down Expand Up @@ -124,17 +129,20 @@ export default {
<td></td>
<td></td>
<td>
<router-link to="/cdb/browse" class="btn btn-success" :disabled="store.busy">
<router-link to="/cdb/browse" class="btn btn-success" :disabled="busy">
<i class="fa-solid fa-box-open"></i>
Add from ContentDB
</router-link>
</td>
</tr>
<tr v-for="mod in store.list">
<tr v-for="mod in get_mods()">
<td>
<span class="badge bg-secondary">{{mod.mod_type}}</span>
</td>
<td>{{mod.name}}</td>
<td>
<cdb-package-link v-if="mod.source_type == 'cdb'" :author="mod.author" :name="mod.name"/>
<span v-else>{{mod.name}}</span>
</td>
<td>
<span class="badge bg-success">
<i class="fa-solid fa-box-open" v-if="mod.source_type == 'cdb'"></i>
Expand Down Expand Up @@ -165,7 +173,7 @@ export default {
Edit
</a>
<a class="btn btn-danger" v-on:click="remove(mod.id)">
<i class="fa fa-times"></i>
<i class="fa fa-trash"></i>
Remove
</a>
</div>
Expand Down
17 changes: 16 additions & 1 deletion public/js/service/mods.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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");
7 changes: 0 additions & 7 deletions public/js/store/mods.js

This file was deleted.

0 comments on commit 071d4ce

Please sign in to comment.