Skip to content

Commit 3f2f921

Browse files
committed
added admin delete project with data feature
1 parent 7026a80 commit 3f2f921

File tree

6 files changed

+97
-1
lines changed

6 files changed

+97
-1
lines changed

appinfo/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
['name' => 'ajax#add_project', 'url' => '/ajax/add-project/{name}', 'verb' => 'POST'],
4141
['name' => 'ajax#edit_project', 'url' => '/ajax/edit-project/{id}', 'verb' => 'POST'],
4242
['name' => 'ajax#delete_project', 'url' => '/ajax/delete-project/{id}', 'verb' => 'POST'],
43+
['name' => 'ajax#delete_project_with_data', 'url' => '/ajax/delete-project-with-data/{id}', 'verb' => 'POST'],
4344

4445

4546
['name' => 'ajax#get_tags', 'url' => '/ajax/tags', 'verb' => 'GET'],

css/style.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ html[xmlns] .clearfix { display: block;}
207207
.project-name{
208208
flex:0.3;
209209
}
210-
210+
button.redButton {
211+
background-color: red;
212+
}
211213
.king-table-region .pagination-bar {
212214
height: 50px;
213215
margin: 20px 0px 20px 0px;

js/projects.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
}
8686

8787
});
88+
} else {
89+
$(".admin-only").hide();
8890
}
8991

9092

@@ -237,6 +239,28 @@
237239
$('input.select2-input').attr('autocomplete', "xxxxxxxxxxx")
238240
},
239241
buttons: {
242+
"Delete project": { text:'Delete project',
243+
click:function(){
244+
245+
$("#dialog-confirm").dialog({
246+
buttons : {
247+
"Confirm" : {click: function() {
248+
deleteProject(dialogProjectEditForm);
249+
$("#dialog-confirm").dialog("close");
250+
},
251+
252+
text: 'Confirm',
253+
class:'primary'
254+
},
255+
"Cancel" : function() {
256+
$(this).dialog("close");
257+
}
258+
}
259+
});
260+
$("#dialog-confirm").dialog('open');
261+
262+
263+
}, class:'redButton admin-only'},
240264
"Edit project": { text:'Edit project',
241265
click:function(){
242266
editProject(dialogProjectEditForm);
@@ -275,6 +299,25 @@
275299
});
276300

277301
}
302+
function deleteProject(dialogProjectEditForm){
303+
target = dialogProjectEditForm.target;
304+
form = dialogProjectEditForm.find( "form" );
305+
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/delete-project-with-data/'+target.getData().id);
306+
var jqxhr = $.post( baseUrl, {name:form.find("#name").val(), clientId:form.find("#client-select-popup").val(), locked:form.find("#locked").is(':checked')?'1':'0',archived:form.find("#archived").is(':checked')?'1':'0', allowedTags:form.find("#locked-select-tags").val(), allowedUsers:form.find("#locked-select-users").val() },function() {
307+
getProjects();
308+
$(dialogProjectEditForm).dialog("close");
309+
})
310+
.done(function(data, status, jqXHR) {
311+
var response = data;
312+
if ('Error' in response){
313+
alert(response.Error);
314+
}
315+
})
316+
.fail(function() {
317+
alert( "error" );
318+
});
319+
320+
}
278321
function getProjects(){
279322
var baseUrl = OC.generateUrl('/apps/timetracker/ajax/projects-table');
280323
// var table = window.kingtable = new KingTable({

lib/Controller/AjaxController.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,25 @@ public function deleteProject($id) {
595595
return $this->getProjects();
596596
}
597597

598+
public function deleteProjectWithData($id) {
599+
if (!$this->isThisAdminUser()){
600+
return;
601+
}
602+
$this->userToProjectMapper->deleteAllForProject($id);
603+
$wi = $this->workIntervalMapper->findAllForProject($id);
604+
if ($wi != null){
605+
foreach ($wi as $w){
606+
$this->workIntervalToTagMapper->deleteAllForWorkInterval($w->id);
607+
}
608+
}
609+
$this->workIntervalMapper->deleteAllForProject($id);
610+
$this->tagMapper->allowedTags($id,[]);
611+
$this->projectMapper->delete($id);
612+
613+
614+
return $this->getProjects();
615+
}
616+
598617

599618
/**
600619
*

lib/Db/ProjectMapper.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ public function findAllAdmin($getArchived = 0){
5656
return $this->findEntities($sql, []);
5757
}
5858

59+
public function delete($project_id) {
60+
$sql = 'delete FROM `*PREFIX*timetracker_project` ' .
61+
' where id = ?';
62+
63+
try {
64+
$this->execute($sql, [$project_id]);
65+
return;
66+
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
67+
return;
68+
}
69+
70+
}
71+
5972

6073

6174

lib/Db/WorkIntervalMapper.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,22 @@ public function stopAllRunning($user, $limit = 100, $offset = 0){
8787
return $this->findEntities($sql, [$user],$limit, $offset);
8888
}
8989

90+
public function findAllForProject($project_id){
91+
$sql = 'SELECT * FROM `*PREFIX*timetracker_work_interval` where project_id = ?';
92+
return $this->findEntities($sql, [$project_id]);
93+
}
94+
95+
public function deleteAllForProject($project_id) {
96+
$sql = 'delete FROM `*PREFIX*timetracker_work_interval` ' .
97+
' where project_id = ?';
98+
99+
try {
100+
$this->execute($sql, [$project_id]);
101+
return;
102+
} catch (\OCP\AppFramework\Db\DoesNotExistException $e){
103+
return;
104+
}
105+
106+
}
107+
90108
}

0 commit comments

Comments
 (0)