Skip to content

Commit

Permalink
Add delete node
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Jul 3, 2017
1 parent ea5ada7 commit 7b3cae1
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 7 deletions.
7 changes: 7 additions & 0 deletions app/Controllers/Api/Admin/NodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public function update(Request $req, Response $res, $args)
return $this->saveModel($res, Node::find($args['id']), $arr);
}

public function delete(Request $req, Response $res, $args)
{
$node = Node::find($args['id']);
$node->delete();
return $this->echoJsonWithData($res, []);
}

public function trafficLogs(Request $req, Response $res, $args)
{
$pageNum = 1;
Expand Down
2 changes: 1 addition & 1 deletion public/assets/js/admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/js/home.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions resources/lang/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

return [
'add' => 'Add',
'delete' => 'Delete',
'action' => 'Action',
'node-add' => 'Add Node',
];
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
$this->put('/admin/config', 'App\Controllers\Api\Admin\ConfigController:update')->add(new Admin());
$this->get('/admin/nodes', 'App\Controllers\Api\Admin\NodeController:index')->add(new Admin());
$this->post('/admin/nodes', 'App\Controllers\Api\Admin\NodeController:store')->add(new Admin());
$this->delete('/admin/nodes/{id}', 'App\Controllers\Api\Admin\NodeController:delete')->add(new Admin());
$this->get('/admin/trafficLogs', 'App\Controllers\Api\Admin\TrafficLogController:index')->add(new Admin());
});

Expand Down
2 changes: 2 additions & 0 deletions src/lang/vue-i18n-locales.generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export default {
},
"admin": {
"add": "Add",
"delete": "Delete",
"action": "Action",
"node-add": "Add Node"
},
"alert": {
Expand Down
26 changes: 22 additions & 4 deletions src/pages/Admin/Node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<div uk-grid class="uk-child-width-1-1@s uk-child-width-1-1@m uk-child-width-1-4@xl">
<div class="uk-card uk-card-default uk-card-body">
<div class="uk-margin">
<router-link tag="li" :to="{ name: 'node-add' }" exact><button class="uk-button uk-button-primary" >
{{$t("admin.node-add")}}
</button></router-link>
<router-link tag="li" :to="{ name: 'node-add' }" exact>
<button class="uk-button uk-button-primary">
{{$t("admin.node-add")}}
</button>
</router-link>
</div>

<table class="uk-table uk-table-striped">
Expand All @@ -23,6 +25,7 @@
<th>{{$t("ss.node")}}</th>
<th>{{$t("ss.server_addr")}}</th>
<th>{{$t("ss.traffic_rate")}}</th>
<th>{{$t("admin.action")}}</th>
</tr>
</thead>
<tbody>
Expand All @@ -31,6 +34,11 @@
<td>{{node.name}}</td>
<td>{{node.server}}</td>
<td>{{node.traffic_rate}}</td>
<td> <div class="uk-margin">
<button class="uk-button uk-button-danger" @click="deleteNode(node.id)">
{{$t("admin.delete")}}
</button>
</div></td>
</tr>
</tbody>
</table>
Expand All @@ -49,7 +57,7 @@
<script>
import admin from '../../http/admin'
import pagination from 'laravel-vue-pagination-uikit'
import {bytesToSize} from '../../tools/util'
import {bytesToSize,notify} from '../../tools/util'
export default {
name: 'Node',
components: {
Expand Down Expand Up @@ -77,6 +85,16 @@
timeFormat(ut){
return new Date(ut * 1e3).toISOString();
},
deleteNode(id){
admin.delete(`nodes/` + id)
.then(response => {
notify(this.$t('base.success'),'primary');
this.Results();
})
.catch(e => {
notify(this.$t('base.something-wrong'),'danger');
})
},
bytesToSize,
},
mounted: function () {
Expand Down
9 changes: 9 additions & 0 deletions src/tools/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ export const bytesToSize = function (bytes) {
};

export const timeFormat = function (t) {
};

export const notify = function(message,status){
UIkit.notification({
message: message,
status: status,
pos: 'top-center',
timeout: 5000
});
};

0 comments on commit 7b3cae1

Please sign in to comment.