Skip to content

Commit 667cb65

Browse files
authored
Merge pull request #106 from Gid733/master
Added functionality to delete, add and update tags
2 parents c7c58b3 + 1521955 commit 667cb65

File tree

14 files changed

+238
-21
lines changed

14 files changed

+238
-21
lines changed

eFormAPI/eFormAPI/Controllers/TagsController.cs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using eFormAPI.Web.Infrastructure.Helpers;
55
using eFormAPI.Web.Infrastructure.Models.API;
66
using eFormAPI.Web.Infrastructure.Models.Common;
7+
using eFormAPI.Web.Infrastructure.Models.Tags;
78

89
namespace eFormAPI.Web.Controllers
910
{
@@ -37,18 +38,54 @@ public OperationDataResult<List<CommonDictionaryModel>> GetAllTags()
3738
}
3839
}
3940

40-
[HttpDelete]
41-
[Route("api/tags")]
42-
public OperationDataResult<bool> DeleteTag(int tagId)
41+
[HttpGet]
42+
[Route("api/tags/delete")]
43+
public OperationResult DeleteTag(int tagId)
4344
{
4445
try
4546
{
4647
var result = _coreHelper.GetCore().TagDelete(tagId);
47-
return new OperationDataResult<bool>(result, result);
48+
return result
49+
? new OperationResult(true, "Tag was deleted successfully")
50+
: new OperationResult(false, "Error while deleted tag");
51+
}
52+
catch (Exception)
53+
{
54+
return new OperationResult(false, "Error while removing tag");
55+
}
56+
}
57+
58+
[HttpPost]
59+
[Route("api/tags")]
60+
public OperationResult CreateTag(string tagName)
61+
{
62+
try
63+
{
64+
var result = _coreHelper.GetCore().TagCreate(tagName);
65+
return result > 0 ?
66+
new OperationResult(true, $"Tag \"{tagName}\" was created successfully")
67+
: new OperationResult(false, $"Error while creating \"{tagName}\" tag");
68+
}
69+
catch (Exception)
70+
{
71+
return new OperationResult(false, $"Error while creating \"{tagName}\" tag");
72+
}
73+
}
74+
75+
[HttpPost]
76+
[Route("api/tags/template")]
77+
public OperationResult UpdateTemplateTags(UpdateTemplateTagsModel requestModel)
78+
{
79+
try
80+
{
81+
var result = _coreHelper.GetCore().TemplateSetTags(requestModel.TemplateId, requestModel.TagsIds);
82+
return result
83+
? new OperationResult(true, "Template tags was updated successfully")
84+
: new OperationResult(false, "Error while updating template tags");
4885
}
4986
catch (Exception)
5087
{
51-
return new OperationDataResult<bool>(false, "Error while deleting tags");
88+
return new OperationResult(false, "Error while updating template tags");
5289
}
5390
}
5491
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace eFormAPI.Web.Infrastructure.Models.Tags
4+
{
5+
public class UpdateTemplateTagsModel
6+
{
7+
public int TemplateId { get; set; }
8+
public List<int> TagsIds { get; set; } = new List<int>();
9+
}
10+
}

eFormAPI/eFormAPI/eFormAPI.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@
325325
<Compile Include="Infrastructure\Models\Settings\Initial\InitialSettingsModel.cs" />
326326
<Compile Include="Infrastructure\Models\SimpleSiteModel.cs" />
327327
<Compile Include="Infrastructure\Models\SiteNameModel.cs" />
328+
<Compile Include="Infrastructure\Models\Tags\UpdateTemplateTagsModel.cs" />
328329
<Compile Include="Infrastructure\Models\Templates\DeployCheckbox.cs" />
329330
<Compile Include="Infrastructure\Models\Templates\DeployModel.cs" />
330331
<Compile Include="Infrastructure\Models\Templates\DeployToModel.cs" />

eform-client/gulpfile.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@ const protractor = require('gulp-protractor').protractor;
22
const gulp = require('gulp');
33
const runSequence = require('run-sequence');
44
const spawn = require('child_process').spawn;
5+
const clean = require('gulp-clean');
56

6-
const runSpawn = function(done, task, opt_arg, opt_io) {
7+
const runSpawn = function (done, task, opt_arg, opt_io) {
78
opt_arg = typeof opt_arg !== 'undefined' ? opt_arg : [];
89
var stdio = 'inherit';
910
if (opt_io === 'ignore') {
1011
stdio = 'ignore';
1112
}
1213
var child = spawn(task, opt_arg, {stdio: stdio});
1314
var running = false;
14-
child.on('close', function() {
15+
child.on('close', function () {
1516
if (!running) {
1617
running = true;
1718
done();
1819
}
1920
});
20-
child.on('error', function() {
21+
child.on('error', function () {
2122
if (!running) {
2223
console.error('gulp encountered a child error');
2324
running = true;
@@ -26,12 +27,12 @@ const runSpawn = function(done, task, opt_arg, opt_io) {
2627
});
2728
};
2829

29-
gulp.task('webdriver:update', function(done) {
30+
gulp.task('webdriver:update', function (done) {
3031
runSpawn(done, 'node', ['./node_modules/protractor/bin/webdriver-manager', 'update']);
3132
});
3233

33-
gulp.task('tests', function(done) {
34-
runSequence(['webdriver:update'], "e2e-tests" ,done);
34+
gulp.task('tests', function (done) {
35+
runSequence(['webdriver:update'], "e2e-tests", done);
3536
});
3637

3738
gulp.task("e2e-tests", function (done) {
@@ -42,3 +43,8 @@ gulp.task("e2e-tests", function (done) {
4243
);
4344
done();
4445
});
46+
// deletes bin/input.txt
47+
gulp.task('input-clean', function () {
48+
gulp.src('../eFormAPI/eFormAPI/bin/input.txt')
49+
.pipe(clean({force: true}))
50+
});

eform-client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"angular-mocks": "^1.6.8",
6262
"codelyzer": "~2.0.0",
6363
"gulp": "^3.9.1",
64+
"gulp-clean": "^0.4.0",
6465
"gulp-protractor": "^4.1.0",
6566
"jasmine-core": "2.5.2",
6667
"jasmine-spec-reporter": "2.5.0",

eform-client/protractor.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
var SpecReporter = require('jasmine-spec-reporter');
66
exports.config = {
77
allScriptsTimeout: 20000,
8+
allScriptsTimeout: 450000,
89
specs: [
910
'./e2e/settings.site-header.e2e-spec.ts'
1011
],
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './deploy.model';
22
export * from './eform-create.model';
3+
export * from './template-tags-update.model';
34

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export class TemplateTagsUpdateModel {
2+
templateId: number;
3+
tagsIds: Array<number> = [];
4+
}

eform-client/src/app/modules/eform/components/eform-page/eform-table.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@
2929
.tags-label {
3030
margin-left: 10px;
3131
}
32+
33+
.new-tag-block {
34+
padding-left: 0px !important;
35+
}

eform-client/src/app/modules/eform/components/eform-page/eform-table.component.html

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,23 @@ <h1 class="page-title header-page-title">
9090
{{templateDto.label}}
9191
</td>
9292
<td class="text-center">
93-
<ng-container *ngFor="let tag of templateDto.tags">
94-
{{tag.value}},
95-
</ng-container>
93+
<div class="row">
94+
<div class="col-md-10">
95+
<ng-container *ngFor="let tag of templateDto.tags; let i = index">
96+
{{tag.value}}
97+
<ng-container *ngIf="templateDto.tags.length - 1 !== i">
98+
,
99+
</ng-container>
100+
</ng-container>
101+
</div>
102+
<div class="col-md-2">
103+
<a (click)="showTemplateTagsEdit(templateDto)"
104+
class="needs_tooltip btn btn-ar btn-xs btn-default"
105+
type="button" tooltip="Edit tags">
106+
<span class="glyphicon glyphicon-pencil"></span>
107+
</a>
108+
</div>
109+
</div>
96110
</td>
97111
<td class="text-center">
98112
<span *ngFor="let deployedSite of templateDto.deployedSites">{{deployedSite.siteName}}<br></span>
@@ -383,6 +397,69 @@ <h4 class="modal-title">Are you sure you want to delete?</h4>
383397
</modal-footer>
384398
</modal>
385399

400+
<modal #updateTemplateTagsModal>
401+
<modal-header [show-close]="true">
402+
<h4 class="modal-title">Select tags for template</h4>
403+
</modal-header>
404+
<modal-body>
405+
<div class="container-fluid">
406+
<div class="row">
407+
<div class="form-group col-xs-12 col-md-12">
408+
<label class="multiselect-label" for="eFormXML">Template tags</label>
409+
<ss-multiselect-dropdown [options]="availableTags"
410+
[texts]="myTexts"
411+
[(ngModel)]="selectedTemplateTagsIds"
412+
[disabled]="isTagsProcessing"
413+
[settings]="mySettings">
414+
</ss-multiselect-dropdown>
415+
</div>
416+
</div>
417+
<div class="row">
418+
<div class="form-group col-xs-12 col-md-12">
419+
<label class="multiselect-label" for="eFormXML">New tag</label>
420+
<div class="col-md-9 col-xs-9 new-tag-block form-group">
421+
<input type="search" class="form-control" #newTagInput>
422+
</div>
423+
<div class="col-md-3 col-xs-3">
424+
<button class="btn btn-success btn-md" [disabled]="isTagsProcessing"
425+
(click)="createNewTag(newTagInput.value); newTagInput.value = ''">
426+
Save
427+
</button>
428+
</div>
429+
</div>
430+
</div>
431+
<div class="row">
432+
<div class="form-group col-xs-12 col-md-12">
433+
<label class="multiselect-label" for="eFormXML">Tag list</label>
434+
<div class="col-md-9 col-xs-9 new-tag-block">
435+
<select class="form-control" #tagRemoveId>
436+
<option *ngFor="let availableTag of availableTags"
437+
[disabled]="isTagsProcessing"
438+
[value]="availableTag.id">
439+
{{availableTag.name}}
440+
</option>
441+
</select>
442+
</div>
443+
<div class="col-md-3 col-xs-3">
444+
<button class="btn btn-danger"
445+
[disabled]="isTagsProcessing"
446+
(click)="removeTemplateTag(tagRemoveId.value)">
447+
Delete
448+
</button>
449+
</div>
450+
</div>
451+
</div>
452+
</div>
453+
</modal-body>
454+
<modal-footer>
455+
<button type="button" class="btn btn-danger" [disabled]="isTagsProcessing"
456+
(click)="updateTemplateTags(selectedTemplateDto.id)">Save</button>
457+
<button type="button" class="btn btn-default" data-dismiss="deleteTemplateModal"
458+
(click)="updateTemplateTagsModal.dismiss()">Cancel
459+
</button>
460+
</modal-footer>
461+
</modal>
462+
386463
<modal #createTemplateModal [size]="'lg'">
387464
<modal-header [show-close]="true">
388465
<h4>Create eForm</h4>
@@ -401,7 +478,9 @@ <h4>Create eForm</h4>
401478
<ng-container *ngIf="isTagAddOpen">
402479
<input type="search" [(ngModel)]="eFormCreateModel.newTag" class="form-control add-tag-input">
403480
<button class="btn btn-danger btn-xs btn-add-tag"
404-
(click)="isTagAddOpen = !isTagAddOpen; eFormCreateModel.newTag = '';"><span class="glyphicon glyphicon-remove"></span></button>
481+
(click)="isTagAddOpen = !isTagAddOpen; eFormCreateModel.newTag = '';">
482+
<span class="glyphicon glyphicon-remove"></span>
483+
</button>
405484
</ng-container>
406485

407486
</div>

0 commit comments

Comments
 (0)