Skip to content

Commit

Permalink
MailSettingRepository.cs - added validation for CC
Browse files Browse the repository at this point in the history
MailSettingController.cs - divided code in region
groupAdd.component.spec.ts - added test case for selectEmail and removeEmail
groupAdd.component.ts - added functionality for selectEmail and removeEmail
groupAdd.html - used material chip and autoselect instead of md2-chip
groupEdit.component.spec.ts - added test case for selectEmail and removeEmail
groupEdit.component.ts - added functionality for selectEmail and removeEmail
groupEdit.html - used material chip and autoselect instead of md2-chip
group.module.ts -  added a provider MaterialAutoSelectChip
mailsetting.component.spec.ts - added test case for group select and remove
mailsetting.component..ts - added group select and remove functionality
mailsetting.html - used material chip and autoselect instead of md2-chip
mailsetting.module.ts - added a provider MaterialAutoSelectChip
angular-material-chip-autoselect.service.ts - added add and remove service from list which are used in material auto select
shared.module.ts - import and export MaterialModule
stringConstant.ts - added 2 string constants
karma-test-shim.js - added reference of material
package.json - added new package -> angular-material - 2.0.0.beta3
system.config.js - added reference of material
erp-custom.css - design for chip and autocomplete
AfterLogIn.cshtml - link for material reference

Fixes - #353
  • Loading branch information
siddharthashw authored and chintans committed May 24, 2017
1 parent ee89533 commit 6294041
Show file tree
Hide file tree
Showing 21 changed files with 359 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public async Task AddMailSettingAsync(MailSettingAC mailSettingAC)
// add list of To
await AddMailSettingMappingAsync(mailSettingAC.To, true, mailSetting.Id, DateTime.UtcNow);
// add list of CC
await AddMailSettingMappingAsync(mailSettingAC.CC, false, mailSetting.Id, DateTime.UtcNow);
if (mailSettingAC.CC != null)
await AddMailSettingMappingAsync(mailSettingAC.CC, false, mailSetting.Id, DateTime.UtcNow);
await _mailSettingMappingDataRepository.SaveChangesAsync();
}

Expand Down Expand Up @@ -113,7 +114,8 @@ public async Task UpdateMailSettingAsync(MailSettingAC mailSettingAC)
// add list of To
await AddMailSettingMappingAsync(mailSettingAC.To, true, previousMailSetting.Id, previousMailSettingMappingCreatedDateTime);
// add list of CC
await AddMailSettingMappingAsync(mailSettingAC.CC, false, previousMailSetting.Id, previousMailSettingMappingCreatedDateTime);
if (mailSettingAC.CC != null)
await AddMailSettingMappingAsync(mailSettingAC.CC, false, previousMailSetting.Id, previousMailSettingMappingCreatedDateTime);
await _mailSettingMappingDataRepository.SaveChangesAsync();
}
#endregion
Expand Down Expand Up @@ -180,4 +182,4 @@ private async Task<List<string>> GetListOfEmailByMailSettingAsync(bool isTo, int
}
#endregion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ namespace Promact.Erp.Core.Controllers
[RoutePrefix("api/mailsetting")]
public class MailSettingController : BaseController
{
#region Private Variable
private IMailSettingRepository _mailSettingRepository;
#endregion

#region Constructor
public MailSettingController(ISingletonStringLiteral stringConstant, IMailSettingRepository mailSettingRepository)
: base(stringConstant)
{
_mailSettingRepository = mailSettingRepository;
}
#endregion

#region Public Methods
/**
* @api {get} api/mailsetting/project
* @apiVersion 1.0.0
Expand Down Expand Up @@ -158,5 +164,6 @@ public async Task<IHttpActionResult> UpdateMailSettingAsync(MailSettingAC mailSe
await _mailSettingRepository.UpdateMailSettingAsync(mailSettingAC);
return Ok();
}
#endregion
}
}
22 changes: 22 additions & 0 deletions Slack.Automation/Promact.Erp.Web/Content/css/erp-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ md2-chips .md2-chips-container {box-shadow: none !important;}
.mail-settings .chip-input-form {width:100%;}
.mail-settings input[type=checkbox]{vertical-align:middle;margin:0;}
.mail-settings .btn{width:100px;}
.mail-settings .mat-chip i.material-icons{ vertical-align: middle;font-size: 20px;margin-top: -4px; padding-left: 4px;cursor:pointer;}
md2-option.md2-selected ,md2-select:focus:not(.md2-select-disabled) .md2-select-trigger ,.md2-autocomplete-trigger.is-focused .md2-autocomplete-placeholder{color:#169F85!important;}
md2-select:focus:not(.md2-select-disabled) .md2-select-trigger{border-color:#169F85!important;}
.md2-autocomplete-trigger.is-focused{border-bottom:2px solid #169F85!important}
Expand Down Expand Up @@ -88,3 +89,24 @@ md2-pagination .md2-pagination li.active {background: #26B99A !important;}

.loader {display: inline-block;font-size: 6rem;animation: 2s rotate infinite linear;width: 1em;height: 1em;position: absolute;top: 38%;left: 57%;margin: -50px 0px 0px -50px;}
.loader circle {fill: transparent;stroke: #4bcf99 ;stroke-width: 0.1em;stroke-linecap: round;stroke-dasharray: 2.3525em 0.4705em;animation: 1.5s strokeDashArray infinite linear, 24s colorBounce infinite linear;}


.mat-chip.mat-primary{ background-color: #e0e0e0;
color: rgba(0,0,0,.87);}

md-option {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
line-height: 48px;
height: 48px;
padding: 0 16px;
font-size: 16px;
font-family: Roboto,Helvetica Neue,sans-serif;
text-align: left;
text-decoration: none;
position: relative;
cursor: pointer;
outline: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Slack ERP</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,32 @@ describe('Group Add Component Test', () => {
expect(groupAddComponent.isExistsGroupName).toBe(false);
}));

it("selectEmail", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupAddComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.selectEmail(stringConstant.groupName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(1);
expect(groupAddComponent.emailHasValue).toBe(true);
}));

it("removeEmail for empty list", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupAddComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.groupModel.Emails = stringConstant.testGroupList;
groupAddComponent.removeEmail(stringConstant.testName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(0);
expect(groupAddComponent.emailHasValue).toBe(false);
}));

it("removeEmail for exist list", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupAddComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.groupModel.Emails = stringConstant.testGroupListMultiValue;
groupAddComponent.removeEmail(stringConstant.testName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(1);
expect(groupAddComponent.emailHasValue).toBe(true);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StringConstant } from '../../shared/stringConstant';
import { GroupService } from '../group.service';
import { GroupModel } from '../group.model';
import { Md2Toast } from 'md2';
import { MaterialAutoSelectChip } from '../../shared/angular-material-chip-autoselect.service';

@Component({
moduleId : module.id,
Expand All @@ -15,11 +16,15 @@ export class GroupAddComponent implements OnInit {
validPattern: any;
isExistsGroupName: boolean;
listOfActiveEmail: Array<string>;
emailHasValue: boolean;

constructor(private router: Router, private stringConstant: StringConstant, private loader: LoaderService, private groupService: GroupService, private toast: Md2Toast) {
constructor(private router: Router, private stringConstant: StringConstant, private loader: LoaderService,
private groupService: GroupService, private toast: Md2Toast, private materialAutoSelectChipService: MaterialAutoSelectChip) {
this.groupModel = new GroupModel();
this.validPattern = this.stringConstant.emailValidPattern;
this.isExistsGroupName = false;
this.emailHasValue = false;
this.groupModel.Emails = new Array<string>();
}

ngOnInit() {
Expand All @@ -28,7 +33,7 @@ export class GroupAddComponent implements OnInit {
this.listOfActiveEmail = result;
this.loader.loader = false;
});

this.emailHasValue = false;
}

addGroup(groupModel: GroupModel) {
Expand Down Expand Up @@ -61,4 +66,18 @@ export class GroupAddComponent implements OnInit {
this.router.navigate(['/group']);
}

selectEmail(email: string) {
this.groupModel.Emails = this.materialAutoSelectChipService.selectGroup(email, this.groupModel.Emails);
this.emailHasValue = true;
}

removeEmail(email: string) {
this.groupModel.Emails = this.materialAutoSelectChipService.removeGroup(email, this.groupModel.Emails);
if (this.groupModel.Emails.length === 0) {
this.emailHasValue = false;
}
else {
this.emailHasValue = true;
}
}
}
34 changes: 18 additions & 16 deletions Slack.Automation/Promact.Erp.Web/app/Group/GroupAdd/groupAdd.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h3>Add Group</h3>
<div class="row">
<label class="col-md-1">Name:</label>
<div class="col-md-3">

<input type="text" class="form-control" [(ngModel)]="groupModel.Name" name="groupName" #groupName="ngModel" (blur)="checkGroupName(groupModel.Name)" required>
<p [hidden]="!(groupName.touched && !groupName.valid && groupName.errors.required)" class="error">Name is required</p>
<p [hidden]="!(isExistsGroupName)" class="error">Group name already exists</p>
Expand All @@ -32,25 +32,27 @@ <h3>Add Group</h3>
<div class="row">
<label class="col-md-1 emails">Emails:</label>
<div class="col-md-10">
<md2-chips [(ngModel)]="groupModel.Emails"
[isRemovable]="true"
[disabled]="false"
placeholder="Email"
name="emails"
#emails="ngModel"
[allowedPattern]="validPattern"
[isAutoComplete]="true"
[autocompleteDataList]="listOfActiveEmail"
required>
</md2-chips>
<p [hidden]="!(emails.touched && !emails.valid && emails.errors.required)" class="error">Atleast one email is required</p>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<md-chip-list (click)="autocomplete.focus()">
<md-chip *ngFor="let email of groupModel.Emails">{{email}}<i class="material-icons" (click)="removeEmail(email)">close</i></md-chip>
<md-input-container>
<input mdInput placeholder="Emails" [mdAutocomplete]="email" #autocomplete ngModel name="Email" #emails="ngModel">
</md-input-container>
<md-autocomplete #email="mdAutocomplete">
<md-option *ngFor="let email of listOfActiveEmail" (click)="selectEmail(email)">{{email}}</md-option>
</md-autocomplete>
</md-chip-list>
</div>
</div>
</div>
<div [hidden]="!(emails.touched && !emailHasValue)" class="error">Atleast one email is required</div>
</div>
</div>
</div>


<div>
<button class="btn-success btn update-btn" (click)="addGroup(groupModel)" [disabled]="!(groupForm.form.valid && !isExistsGroupName)">Submit</button>
<button class="btn-success btn update-btn" (click)="addGroup(groupModel)" [disabled]="!(groupForm.form.valid && !isExistsGroupName && emailHasValue)">Submit</button>
</div>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,33 @@ describe('Group Edit Component Test', () => {
expect(groupModel.Name).toBe(stringConstant.testGroupName);
}));

it("selectEmail", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupEditComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.groupModel.Emails = new Array<string>();
groupAddComponent.selectEmail(stringConstant.groupName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(1);
expect(groupAddComponent.emailHasValue).toBe(true);
}));

it("removeEmail for empty list", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupEditComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.groupModel.Emails = stringConstant.testGroupList;
groupAddComponent.removeEmail(stringConstant.testName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(0);
expect(groupAddComponent.emailHasValue).toBe(false);
}));

it("removeEmail for exist list", fakeAsync(() => {
let fixture = TestBed.createComponent(GroupEditComponent);
let groupAddComponent = fixture.componentInstance;
groupAddComponent.groupModel.Emails = stringConstant.testGroupListMultiValue;
groupAddComponent.removeEmail(stringConstant.testName);
tick();
expect(groupAddComponent.groupModel.Emails.length).toBe(1);
expect(groupAddComponent.emailHasValue).toBe(true);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { StringConstant } from '../../shared/stringConstant';
import { GroupService } from '../group.service';
import { GroupModel } from '../group.model';
import { Md2Toast } from 'md2';
import { MaterialAutoSelectChip } from '../../shared/angular-material-chip-autoselect.service';

@Component({
moduleId: module.id,
Expand All @@ -16,11 +17,15 @@ export class GroupEditComponent implements OnInit {
isExistsGroupName: boolean;
id: number;
listOfActiveEmail: Array<string>;
emailHasValue: boolean;

constructor(private router: Router, private route: ActivatedRoute, private stringConstant: StringConstant, private loader: LoaderService, private groupService: GroupService, private toast: Md2Toast) {
constructor(private router: Router, private route: ActivatedRoute, private stringConstant: StringConstant,
private loader: LoaderService, private groupService: GroupService, private toast: Md2Toast,
private materialAutoSelectChipService: MaterialAutoSelectChip) {
this.validPattern = this.stringConstant.emailValidPattern;
this.groupModel = new GroupModel();
this.isExistsGroupName = false;
this.emailHasValue = false;
}

ngOnInit() {
Expand Down Expand Up @@ -53,6 +58,7 @@ export class GroupEditComponent implements OnInit {
this.backToGroupList();
this.toast.show('Group updated successfully.');
this.loader.loader = false;
this.emailHasValue = true;
}, err => {
this.toast.show('Group must not be updated.');
this.loader.loader = false;
Expand All @@ -75,4 +81,19 @@ export class GroupEditComponent implements OnInit {
backToGroupList() {
this.router.navigate(['/group']);
}

selectEmail(email: string) {
this.groupModel.Emails = this.materialAutoSelectChipService.selectGroup(email, this.groupModel.Emails);
this.emailHasValue = true;
}

removeEmail(email: string) {
this.groupModel.Emails = this.materialAutoSelectChipService.removeGroup(email, this.groupModel.Emails);
if (this.groupModel.Emails.length === 0) {
this.emailHasValue = false;
}
else {
this.emailHasValue = true;
}
}
}
31 changes: 17 additions & 14 deletions Slack.Automation/Promact.Erp.Web/app/Group/GroupEdit/groupEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,33 @@ <h3>Edit Group</h3>
<p [hidden]="!(isExistsGroupName)" class="error">Group name already exists</p>
</div>
</div>

</div>

<div class="form-group">
<div class="row">
<label class="col-md-1 emails">Emails:</label>
<div class="col-md-10">
<md2-chips [(ngModel)]="groupModel.Emails"
[isRemovable]="true"
[disabled]="false"
placeholder="Email"
[allowedPattern]="validPattern"
name="emails"
#emails="ngModel"
[isAutoComplete]="true"
[autocompleteDataList]="listOfActiveEmail"
required>
</md2-chips>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<md-chip-list (click)="autocomplete.focus()">
<md-chip *ngFor="let email of groupModel.Emails">{{email}}<i class="material-icons" (click)="removeEmail(email)">close</i></md-chip>
<md-input-container>
<input mdInput placeholder="Emails" [mdAutocomplete]="email" #autocomplete ngModel name="Email" #emails="ngModel">
</md-input-container>
<md-autocomplete #email="mdAutocomplete">
<md-option *ngFor="let email of listOfActiveEmail" (click)="selectEmail(email)">{{email}}</md-option>
</md-autocomplete>
</md-chip-list>
</div>
</div>
</div>
<div [hidden]="!(emails.touched && !emailHasValue)" class="error">Atleast one email is required</div>
</div>
<div [hidden]="!(emails.touched && !emails.valid && emails.errors.required)" class="error">Atleast one email is required</div>
</div>
</div>
<div>
<button class="btn btn-success update-btn" (click)="updateGroup(groupModel)" [disabled]="!(groupForm.form.valid && !isExistsGroupName)">Update</button>
<button class="btn btn-success update-btn" (click)="updateGroup(groupModel)" [disabled]="!(groupForm.form.valid && !isExistsGroupName && emailHasValue)">Update</button>
</div>
</form>
</div>
Expand Down
Loading

0 comments on commit 6294041

Please sign in to comment.