diff --git a/src/packages/MarketPlace/dialog.ts b/src/packages/MarketPlace/dialog.ts index bfada60..8b3a9f0 100644 --- a/src/packages/MarketPlace/dialog.ts +++ b/src/packages/MarketPlace/dialog.ts @@ -39,18 +39,14 @@ namespace OS { { text: "+", onbtclick: () => { - return this.openDialog("PromptDialog", { + return this.openDialog("MultiInputDialog", { title: __("Add repository"), - label: __("Format : [name] url") - }).then(e => { - const m = e.match(/\[([^\]]*)\]\s*(.+)/); - if (!m || (m.length !== 3)) { - return this.error(__("Wrong format: it should be [name] url")); + model: { + text: "Repository name", + url: "Repository URL" } - const repo = { - url: m[2], - text: m[1] - }; + }).then(e => { + const repo = e; this.systemsetting.system.repositories.push(repo); return this.list.push(repo); }); @@ -82,17 +78,17 @@ namespace OS { if (!(selidx >= 0)) { return; } const data = el.data; const sel = this.systemsetting.system.repositories[selidx]; - this.openDialog("PromptDialog", { + this.openDialog("MultiInputDialog", { title: __("Edit repository"), - label: __("Format : [name] url"), - value: `[${data.text}] ${data.url}` + model: { + text: "Repository name", + url: "Repository URL" + }, + allow_empty: false, + data: data }).then(e => { - const m = e.match(/\[([^\]]*)\]\s*(.+)/); - if (!m || (m.length !== 3)) { - return this.error(__("Wrong format: it should be [name] url")); - } - data.text = m[1]; - data.url = m[2]; + data.text = e.text; + data.url = e.url; this.list.update(undefined); return this.list.unselect(); }); diff --git a/src/packages/MarketPlace/main.ts b/src/packages/MarketPlace/main.ts index 1c974f4..12b03da 100644 --- a/src/packages/MarketPlace/main.ts +++ b/src/packages/MarketPlace/main.ts @@ -15,6 +15,7 @@ // You should have received a copy of the GNU General Public License //along with this program. If not, see https://www.gnu.org/licenses/. + namespace OS { export namespace application { declare var showdown: any; @@ -23,6 +24,7 @@ namespace OS { private installdir: string; private apps_meta: GenericObject; private applist: GUI.tag.ListViewTag; + private catlist: GUI.tag.ListViewTag; private container: GUI.tag.VBoxTag; private appname: GUI.tag.LabelTag; private appdetail: HTMLUListElement; @@ -42,11 +44,55 @@ namespace OS { this.apps_meta = []; this.applist = this.find("applist") as GUI.tag.ListViewTag; + this.catlist = this.find("catlist") as GUI.tag.ListViewTag; this.applist.onlistselect = (e) => { const data = e.data.item.data; return this.appDetail(data); }; + this.catlist.onlistselect = (e) => { + const selected = this.catlist.selected; + if(selected < 0) + return; + if(selected === 0) + { + return this.resetAppList(); + } + const result = []; + if(selected === 1) + { + for(const k in this.apps_meta) + { + const pkg = this.apps_meta[k]; + // check if update is available for this application + const version: Version = pkg.version.__v(); + const name = pkg.pkgname ? pkg.pkgname: pkg.app; + if(name && OS.setting.system.packages[name]) + { + const curr_version: Version = OS.setting.system.packages[name].version.__v(); + if(version.compare(curr_version) === 1) + { + result.push(pkg); + } + } + } + } + else + { + // search application by category + const cat = this.catlist.selectedItem.data.text.__(); + for(const k in this.apps_meta) + { + const v = this.apps_meta[k]; + if(v.category.__() === cat) + { + result.push(v); + } + } + } + this.applist.data = result; + }; + this.container = this.find("container") as GUI.tag.VBoxTag; this.appname = this.find("appname") as GUI.tag.LabelTag; this.appdesc = this.find("app-desc") as HTMLParagraphElement; @@ -103,6 +149,25 @@ namespace OS { }); } + private resetAppList(): void + { + let result = []; + for(let k in this.apps_meta) + { + result.push(this.apps_meta[k]); + } + this.applist.data = result.sort( + function (a: GenericObject, b: GenericObject): number { + if (a.text > b.text) { + return 1; + } + if (b.text > a.text) { + return -1; + } + return 0; + }); + } + private search(e: JQuery.KeyboardEventBase) { let k: string; switch (e.which) { @@ -119,20 +184,17 @@ namespace OS { case 13: return e.preventDefault(); default: + this.catlist.selected = 0; var text = this.searchbox.value; + var result = []; if (text.length === 2) { - this.applist.data = (() => { - const result1 = []; - for (k in this.apps_meta) { - result1.push(this.apps_meta[k]); - } - return result1; - })(); + this.resetAppList(); + return; } if (text.length < 3) { return; } - var result = []; + var term = new RegExp(text, "i"); for (k in this.apps_meta) { if (this.apps_meta[k].text.match(term)) { @@ -154,11 +216,9 @@ namespace OS { private loadRemoteRepository(url: string): Promise> { return new Promise((resolve, reject) => { url.asFileHandle().read('json') - //this._api - //.get(url + "?_=" + new Date().getTime(), "json") .then((d) => { for (let v of d) { - v.text = `${v.name} v${v.version}`; + v.text = `${v.name} ${v.version}`; v.iconclass = "fa fa-adn"; v.dependBy = []; if (!v.dependencies) { @@ -231,6 +291,44 @@ namespace OS { }); } + buildAppCats(): void { + let k: string, v: API.PackageMetaType; + const catlist = new Set(); + for (k in this.apps_meta) { + v = this.apps_meta[k]; + if (v) { + catlist.add(v.category.__()); + } + } + // build up the category menu + const cat_list_data = []; + cat_list_data.push({ + text: "__(All)", + iconclass: "bi bi-gear-wide" + }); + cat_list_data.push({ + text: "__(Update)", + iconclass: "bi bi-cloud-arrow-down-fill" + }); + (OS.setting.applications.categories as Array>) + .forEach((v) =>{ + if(catlist.has(v.text.__())) + { + cat_list_data.push({text: v.text, iconclass: v.iconclass}); + catlist.delete(v.text.__()); + } + }) + // put the remainder to the data + catlist.forEach((c) => { + cat_list_data.push({ + text: c, + iconclass: "bi bi-gear-wide" + }); + }); + this.catlist.data = cat_list_data; + this.catlist.selected = 0; + } + fetchApps(): Promise> { return new Promise((resolve, _reject) => { let v: API.PackageMetaType; @@ -241,7 +339,7 @@ namespace OS { this.apps_meta[`${k}@${v.version}`] = { pkgname: v.pkgname ? v.pkgname : v.app, name: v.name, - text: `${v.name} v${v.version}`, + text: `${v.name} ${v.version}`, icon: v.icon, iconclass: v.iconclass, category: v.category, @@ -259,16 +357,7 @@ namespace OS { } this.loadRemoteRepositories(list) .then((apps_list) => { - this.applist.data = apps_list.sort( - function (a: GenericObject, b: GenericObject): number { - if (a.text > b.text) { - return 1; - } - if (b.text > a.text) { - return -1; - } - return 0; - }); + this.buildAppCats(); resolve(this.apps_meta); }); }); diff --git a/src/packages/MarketPlace/package.json b/src/packages/MarketPlace/package.json index 5765e0e..e113f86 100644 --- a/src/packages/MarketPlace/package.json +++ b/src/packages/MarketPlace/package.json @@ -1,4 +1,5 @@ { + "pkgname":"MarketPlace", "app":"MarketPlace", "name":"AntOS Application store", "description":"Application store", @@ -6,7 +7,7 @@ "author": "Xuan Sang LE", "email": "xsang.le@gmail.com" }, - "version":"0.2.3-a", + "version":"0.2.4-a", "category":"System", "iconclass":"fa fa-shopping-bag", "mimes":["none"], diff --git a/src/packages/MarketPlace/scheme.html b/src/packages/MarketPlace/scheme.html index 98bf713..7e63cba 100644 --- a/src/packages/MarketPlace/scheme.html +++ b/src/packages/MarketPlace/scheme.html @@ -1,28 +1,31 @@ - - - - -
- -
- -
- - - - -
- - - -

-
-
-
-

-
    + + + + +
    + +
    + + + + + +
    + + + + +
    + + + +

    -
    - -
    -
    \ No newline at end of file + +
    +

    +
      +
      + + + \ No newline at end of file