Skip to content

Commit 7b3cae1

Browse files
committed
Add delete node
1 parent ea5ada7 commit 7b3cae1

9 files changed

Lines changed: 46 additions & 7 deletions

File tree

app/Controllers/Api/Admin/NodeController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ public function update(Request $req, Response $res, $args)
4949
return $this->saveModel($res, Node::find($args['id']), $arr);
5050
}
5151

52+
public function delete(Request $req, Response $res, $args)
53+
{
54+
$node = Node::find($args['id']);
55+
$node->delete();
56+
return $this->echoJsonWithData($res, []);
57+
}
58+
5259
public function trafficLogs(Request $req, Response $res, $args)
5360
{
5461
$pageNum = 1;

public/assets/js/admin.js

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

public/assets/js/app.js

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

public/assets/js/home.js

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

resources/lang/en/admin.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
return [
44
'add' => 'Add',
5+
'delete' => 'Delete',
6+
'action' => 'Action',
57
'node-add' => 'Add Node',
68
];

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
$this->put('/admin/config', 'App\Controllers\Api\Admin\ConfigController:update')->add(new Admin());
110110
$this->get('/admin/nodes', 'App\Controllers\Api\Admin\NodeController:index')->add(new Admin());
111111
$this->post('/admin/nodes', 'App\Controllers\Api\Admin\NodeController:store')->add(new Admin());
112+
$this->delete('/admin/nodes/{id}', 'App\Controllers\Api\Admin\NodeController:delete')->add(new Admin());
112113
$this->get('/admin/trafficLogs', 'App\Controllers\Api\Admin\TrafficLogController:index')->add(new Admin());
113114
});
114115

src/lang/vue-i18n-locales.generated.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export default {
77
},
88
"admin": {
99
"add": "Add",
10+
"delete": "Delete",
11+
"action": "Action",
1012
"node-add": "Add Node"
1113
},
1214
"alert": {

src/pages/Admin/Node.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
<div uk-grid class="uk-child-width-1-1@s uk-child-width-1-1@m uk-child-width-1-4@xl">
1212
<div class="uk-card uk-card-default uk-card-body">
1313
<div class="uk-margin">
14-
<router-link tag="li" :to="{ name: 'node-add' }" exact><button class="uk-button uk-button-primary" >
15-
{{$t("admin.node-add")}}
16-
</button></router-link>
14+
<router-link tag="li" :to="{ name: 'node-add' }" exact>
15+
<button class="uk-button uk-button-primary">
16+
{{$t("admin.node-add")}}
17+
</button>
18+
</router-link>
1719
</div>
1820

1921
<table class="uk-table uk-table-striped">
@@ -23,6 +25,7 @@
2325
<th>{{$t("ss.node")}}</th>
2426
<th>{{$t("ss.server_addr")}}</th>
2527
<th>{{$t("ss.traffic_rate")}}</th>
28+
<th>{{$t("admin.action")}}</th>
2629
</tr>
2730
</thead>
2831
<tbody>
@@ -31,6 +34,11 @@
3134
<td>{{node.name}}</td>
3235
<td>{{node.server}}</td>
3336
<td>{{node.traffic_rate}}</td>
37+
<td> <div class="uk-margin">
38+
<button class="uk-button uk-button-danger" @click="deleteNode(node.id)">
39+
{{$t("admin.delete")}}
40+
</button>
41+
</div></td>
3442
</tr>
3543
</tbody>
3644
</table>
@@ -49,7 +57,7 @@
4957
<script>
5058
import admin from '../../http/admin'
5159
import pagination from 'laravel-vue-pagination-uikit'
52-
import {bytesToSize} from '../../tools/util'
60+
import {bytesToSize,notify} from '../../tools/util'
5361
export default {
5462
name: 'Node',
5563
components: {
@@ -77,6 +85,16 @@
7785
timeFormat(ut){
7886
return new Date(ut * 1e3).toISOString();
7987
},
88+
deleteNode(id){
89+
admin.delete(`nodes/` + id)
90+
.then(response => {
91+
notify(this.$t('base.success'),'primary');
92+
this.Results();
93+
})
94+
.catch(e => {
95+
notify(this.$t('base.something-wrong'),'danger');
96+
})
97+
},
8098
bytesToSize,
8199
},
82100
mounted: function () {

src/tools/util.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,13 @@ export const bytesToSize = function (bytes) {
77
};
88

99
export const timeFormat = function (t) {
10+
};
11+
12+
export const notify = function(message,status){
13+
UIkit.notification({
14+
message: message,
15+
status: status,
16+
pos: 'top-center',
17+
timeout: 5000
18+
});
1019
};

0 commit comments

Comments
 (0)