Skip to content

Commit aa61afb

Browse files
committed
Add proper server models
1 parent 6e5c365 commit aa61afb

File tree

7 files changed

+228
-50
lines changed

7 files changed

+228
-50
lines changed

app/Transformers/Api/Client/ServerTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function transform(Server $server): array
2828
'identifier' => $server->uuidShort,
2929
'uuid' => $server->uuid,
3030
'name' => $server->name,
31+
'node' => $server->node->name,
3132
'description' => $server->description,
3233
'allocation' => [
3334
'ip' => $server->allocation->alias,

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"laracasts/utilities": "^3.0",
2727
"laravel/framework": "5.6.*",
2828
"laravel/tinker": "^1.0",
29+
"lcobucci/jwt": "^3.2",
2930
"lord/laroute": "^2.4",
3031
"matriphe/iso-639": "^1.2",
3132
"nesbot/carbon": "^1.22",

composer.lock

Lines changed: 59 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@
2424
"gulp-rev": "^8.1.1",
2525
"gulp-uglify-es": "^1.0.1",
2626
"jquery": "^3.3.1",
27+
"jwt-decode": "^2.2.0",
2728
"lodash": "^4.17.5",
2829
"postcss": "^6.0.21",
2930
"postcss-import": "^11.1.0",
3031
"postcss-preset-env": "^3.4.0",
3132
"postcss-scss": "^1.0.4",
3233
"tailwindcss": "^0.5.1",
34+
"vee-validate": "^2.0.9",
3335
"vue": "^2.5.7",
3436
"vue-axios": "^2.1.1",
3537
"vue-devtools": "^3.1.9",
3638
"vue-loader": "^14.2.2",
39+
"vue-mc": "^0.2.4",
3740
"vue-router": "^3.0.1",
3841
"vue-template-compiler": "^2.5.16",
3942
"vueify-insert-css": "^1.0.0",

resources/assets/scripts/components/dashboard/Dashboard.vue

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/>
99
</div>
1010
<transition-group class="w-full m-auto mt-4 animate fadein sm:flex flex-wrap content-start">
11-
<div class="server-box" :key="index" v-for="(server, index) in servers">
11+
<div class="server-box" :key="index" v-for="(server, index) in servers.models">
1212
<router-link :to="{ name: 'server', params: { id: server.identifier }}" class="content">
1313
<div class="float-right">
1414
<div class="indicator"></div>
@@ -38,7 +38,7 @@
3838
</div>
3939
<div class="flex items-center">
4040
<div class="text-sm">
41-
<p class="text-grey">{{ server.node_name }}</p>
41+
<p class="text-grey">{{ server.node }}</p>
4242
<p class="text-grey-dark">{{ server.allocation.ip }}:{{ server.allocation.port }}</p>
4343
</div>
4444
</div>
@@ -49,15 +49,15 @@
4949
</template>
5050

5151
<script>
52-
import Server from '../../models/server';
52+
import { ServerCollection } from '../../models/server';
5353
import _ from 'lodash';
5454
5555
export default {
5656
name: 'dashboard',
5757
data: function () {
5858
return {
5959
search: '',
60-
servers: [],
60+
servers: new ServerCollection,
6161
}
6262
},
6363
@@ -72,18 +72,16 @@
7272
* @param {string} query
7373
*/
7474
loadServers: function (query = '') {
75-
const self = this;
76-
7775
window.axios.get(this.route('api.client.index'), {
7876
params: { query },
7977
})
80-
.then(function (response) {
81-
self.servers = [];
82-
response.data.data.forEach(function (obj) {
83-
self.servers.push(new Server().fill(obj.attributes))
78+
.then(response => {
79+
this.servers = new ServerCollection;
80+
response.data.data.forEach(obj => {
81+
this.servers.add(obj.attributes);
8482
});
8583
})
86-
.catch(function (error) {
84+
.catch(error => {
8785
console.error(error);
8886
});
8987
},
Lines changed: 111 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,114 @@
1-
import Allocation from './allocation';
2-
3-
const Server = function () {
4-
this.identifier = null;
5-
this.uuid = null;
6-
this.name = '';
7-
this.description = '';
8-
this.allocation = null;
9-
this.limits = {
10-
memory: 0,
11-
swap: 0,
12-
disk: 0,
13-
io: 0,
14-
cpu: 0,
15-
};
16-
this.feature_limits = {
17-
databases: 0,
18-
allocations: 0,
19-
};
20-
};
1+
import { Collection, Model } from 'vue-mc';
212

223
/**
23-
* Return a new server model filled with data from the provided object.
24-
*
25-
* @param {object} obj
26-
* @returns {Server}
4+
* A generic server model used throughout the code base.
275
*/
28-
Server.prototype.fill = function (obj) {
29-
this.identifier = obj.identifier;
30-
this.uuid = obj.uuid;
31-
this.name = obj.name;
32-
this.description = obj.description;
33-
this.allocation = new Allocation().fill(obj.allocation || {});
34-
this.limits = obj.limits;
35-
this.feature_limits = obj.feature_limits;
36-
37-
return this;
38-
};
39-
40-
export default Server;
6+
export class Server extends Model {
7+
/**
8+
* Identifier the primary identifier for this model.
9+
*
10+
* @returns {{identifier: string}}
11+
*/
12+
static options() {
13+
return {
14+
identifier: 'identifier',
15+
};
16+
}
17+
18+
/**
19+
* Return the defaults for this model.
20+
*
21+
* @returns {object}
22+
*/
23+
static defaults() {
24+
return {
25+
uuid: null,
26+
identifier: null,
27+
name: '',
28+
description: '',
29+
node: '',
30+
limits: {
31+
memory: 0,
32+
swap: 0,
33+
disk: 0,
34+
io: 0,
35+
cpu: 0,
36+
},
37+
allocation: {
38+
ip: null,
39+
port: null,
40+
},
41+
feature_limits: {
42+
databases: 0,
43+
allocations: 0,
44+
},
45+
};
46+
}
47+
48+
/**
49+
* Mutations to apply to items in this model.
50+
*
51+
* @returns {{name: StringConstructor, description: StringConstructor}}
52+
*/
53+
static mutations() {
54+
return {
55+
uuid: String,
56+
identifier: String,
57+
name: String,
58+
description: String,
59+
node: String,
60+
limits: {
61+
memory: Number,
62+
swap: Number,
63+
disk: Number,
64+
io: Number,
65+
cpu: Number,
66+
},
67+
allocation: {
68+
ip: String,
69+
port: Number,
70+
},
71+
feature_limits: {
72+
databases: Number,
73+
allocations: Number,
74+
}
75+
};
76+
}
77+
78+
/**
79+
* Routes to use when building models.
80+
*
81+
* @returns {{fetch: string}}
82+
*/
83+
static routes() {
84+
return {
85+
fetch: '/api/client/servers/{identifier}',
86+
};
87+
}
88+
}
89+
90+
export class ServerCollection extends Collection {
91+
static model() {
92+
return Server;
93+
}
94+
95+
static defaults() {
96+
return {
97+
orderBy: identifier,
98+
};
99+
}
100+
101+
static routes() {
102+
return {
103+
fetch: '/api/client',
104+
};
105+
}
106+
107+
get todo() {
108+
return this.sum('done');
109+
}
110+
111+
get done() {
112+
return this.todo === 0;
113+
}
114+
}

0 commit comments

Comments
 (0)