Skip to content

Commit

Permalink
add delete action
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarzin committed Nov 10, 2024
1 parent e14c7e3 commit 835985b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
25 changes: 25 additions & 0 deletions app/Http/Controllers/ActionplanController.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,29 @@ public function export()
);
}

public function delete() {
// For administrators and users only
abort_if(
Auth::User()->role !== 1 && Auth::User()->rol !== 2,
Response::HTTP_FORBIDDEN,
'403 Forbidden'
);

// Get the action plan
$id = (int)request('id');
$action = Action::find($id);

// Action not found
abort_if($action === null, Response::HTTP_NOT_FOUND, '404 Not Found');

// delete links
DB::table('action_measure')->where('action_id', $action->id)->delete();

// delete
$action->delete();

// Return
return redirect('/actions');
}

}
17 changes: 12 additions & 5 deletions resources/views/actions/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,26 @@
{{ trans('common.save') }}
</button>
&nbsp;
<a class="button primary" href="/action/close/{{ $action->id }}">
<a class="button info" href="/action/close/{{ $action->id }}">
<span class="mif-done"></span>
&nbsp;
{{ trans("common.close") }}
</a>
&nbsp;
@endif
<a class="button alert" href="/action/edit/{{ $action->id }}">
<span class="mif-wrench"></span>
&nbsp;
{{ trans("common.edit") }}
<a class="button primary" href="/action/edit/{{ $action->id }}">
<span class="mif-wrench"></span>
&nbsp;
{{ trans('common.edit') }}
</a>
&nbsp;
<button class="button alert" type="submit" onclick='this.form.action="/action/delete"'
onSubmit="if(!confirm('{{ trans('common.confirm') }}')){return false;}">
<span class="mif-fire"></span>
&nbsp;
{{ trans('common.delete') }}
</button>
&nbsp;
<a class="button dafault" href="/actions">
<span class="mif-cancel"></span>
&nbsp;
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
Route::post('/action/update', 'ActionplanController@update');
Route::post('/action/save', 'ActionplanController@save');
Route::post('/action/close', 'ActionplanController@doClose');
Route::post('/action/delete', 'ActionplanController@delete');

/* Reports */
Route::get('/reports', 'ReportController@show');
Expand Down

0 comments on commit 835985b

Please sign in to comment.