diff --git a/client/src/dev/serveremu.js b/client/src/dev/serveremu.js index 58b1e63a..fb71edfd 100644 --- a/client/src/dev/serveremu.js +++ b/client/src/dev/serveremu.js @@ -65,6 +65,69 @@ export default class ServerEmu { } } + static async plugins(args) { + if (!this._plugins) this._plugins = this.generatePlugins(); + + await new Promise(r => setTimeout(r, Math.random() * 3000)); + + let docs = []; + + if (args && args.sterm) { + const { sterm } = args; + const reg = new RegExp(sterm, 'gi'); + docs = this._plugins.filter(doc => doc.tags.includes(sterm) || reg.exec(doc.name) || reg.exec(doc.description)); + } else { + docs = this._plugins; + } + + if (args.sort) { + switch (args.sort) { + case 'updated': + if (args.ascending) docs = docs.sort((docA, docB) => new Date(docA.updated).getTime() - new Date(docB.updated).getTime()); + else docs = docs.sort((docA, docB) => new Date(docB.updated).getTime() - new Date(docA.updated).getTime()); + break; + case 'installs': + if (args.ascending) docs = docs.sort((docA, docB) => docA.installs - docB.installs); + else docs = docs.sort((docA, docB) => docB.installs - docA.installs); + break; + case 'users': + if (args.ascending) docs = docs.sort((docA, docB) => docA.activeUsers - docB.activeUsers); + else docs = docs.sort((docA, docB) => docB.activeUsers - docA.activeUsers); + break; + case 'rating': + if (args.ascending) docs = docs.sort((docA, docB) => docA.rating - docB.rating); + else docs = docs.sort((docA, docB) => docB.rating - docA.rating); + break; + } + } + + const total = docs.length; + const pages = Math.ceil(total / 9); + + let page = 1; + if (args && args.page) { + page = args.page; + docs = docs.slice((page - 1) * 9, page * 9); + } else { + docs = docs.slice(0, 9); + } + + return { + docs, + filters: { + sterm: args.sterm || '', + ascending: args.ascending || false, + sort: args.sort || 'name' + }, + pagination: { + total, + pages, + limit: 9, + page + } + } + } + static generateThemes() { const docs = []; const count = Math.floor(Math.random() * 50 + 30); @@ -94,6 +157,35 @@ export default class ServerEmu { return docs; } + static generatePlugins() { + const docs = []; + const count = Math.floor(Math.random() * 50 + 30); + + for (let i = 0; i < count; i++) { + const id = `plugin${i}-${this.randomId()}`; + const name = `Dummy Plugin ${i}`; + const tags = dummyTags.sort(() => .5 - Math.random()).slice(0, 3); + + docs.push({ + id, + name, + tags, + installs: Math.floor(Math.random() * 5000) + 5000, + updated: this.randomTimestamp(), + rating: Math.floor(Math.random() * 500) + 500, + activeUsers: Math.floor(Math.random() * 1000) + 1000, + rated: Math.random() > .5, + version: this.randomVersion(), + repository: this.dummyRepo, + files: this.dummyFiles, + author: this.dummyAuthor, + description: '' + }); + } + + return docs; + } + static get dummyRepo() { return { name: 'ExampleRepository', diff --git a/client/src/modules/bdwebapi.js b/client/src/modules/bdwebapi.js index 926b2cb6..9274afb7 100644 --- a/client/src/modules/bdwebapi.js +++ b/client/src/modules/bdwebapi.js @@ -29,6 +29,12 @@ export default class BdWebApi { }; } + static get plugins() { + return { + get: this.getPlugins + }; + } + static get users() { return { get: this.getUsers @@ -54,6 +60,10 @@ export default class BdWebApi { */ } + static getPlugins(args) { + return ServerEmu.plugins(args); + } + static getUsers(args) { if (!args) return request.get(ENDPOINTS.users); const { id } = args; diff --git a/client/src/ui/components/bd/PluginsView.vue b/client/src/ui/components/bd/PluginsView.vue index 16226dbb..92758bc8 100644 --- a/client/src/ui/components/bd/PluginsView.vue +++ b/client/src/ui/components/bd/PluginsView.vue @@ -28,18 +28,31 @@
-
-
- +
+
+
+
+
+
{{searchHint}}
+
+ +
-
-
+
+
+
+ {{btn}} +
+
- -
-
+ +
+
@@ -49,28 +62,45 @@