From c6e2e8aec4e6514402df1423242558233901446f Mon Sep 17 00:00:00 2001 From: Ioannis Kalyvas Date: Wed, 24 Jan 2018 16:11:09 +0200 Subject: [PATCH] no message --- .../java/eu/eudat/controllers/Datasets.java | 9 ++-- .../java/eu/eudat/services/ApiContext.java | 2 + .../eu/eudat/services/ApiContextImpl.java | 11 +++++ .../src/main/resources/messages.properties | 3 +- .../src/main/resources/messages_el.properties | 10 ++++- .../dynamic-form-field.component.ts | 7 +++- .../app/invitation/invitation.component.ts | 4 +- .../visibility-rules/models/VisibilityRule.ts | 6 +-- .../visibility-rules.service.ts | 42 ++++++++++++------- 9 files changed, 66 insertions(+), 28 deletions(-) diff --git a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java index 9d67039f5..fbff55541 100644 --- a/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java @@ -2,6 +2,7 @@ package eu.eudat.controllers; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.UUID; import eu.eudat.entities.DMP; @@ -40,7 +41,8 @@ public class Datasets extends BaseController { } @RequestMapping(method = RequestMethod.POST, value = {"/datasets/getPaged"}, consumes = "application/json", produces = "application/json") - public @ResponseBody ResponseEntity>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) { + public @ResponseBody + ResponseEntity>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) { try { DataTableData dataTable = new DatasetManager().getPaged(this.getApiContext(), datasetTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); @@ -53,10 +55,11 @@ public class Datasets extends BaseController { @Transactional @RequestMapping(method = RequestMethod.GET, value = {"/datasets/makepublic/{id}"}, produces = "application/json") - public @ResponseBody ResponseEntity> makePublic(@PathVariable UUID id, Principal principal) { + public @ResponseBody + ResponseEntity> makePublic(@PathVariable UUID id, Principal principal, Locale locale) { try { DatasetManager.makePublic(this.getApiContext().getDatabaseRepository().getDatasetDao(), id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset Has Been Made Public")); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getMessageSource().getMessage("dataset.public", new Object[]{}, locale))); } catch (Exception ex) { ex.printStackTrace(); diff --git a/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java b/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java index 5f7cc8c78..6aba099df 100644 --- a/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java +++ b/dmp-backend/src/main/java/eu/eudat/services/ApiContext.java @@ -2,6 +2,7 @@ package eu.eudat.services; import eu.eudat.proxy.fetching.RemoteFetcher; import org.springframework.context.ApplicationContext; +import org.springframework.context.MessageSource; /** * Created by ikalyvas on 1/3/2018. @@ -12,4 +13,5 @@ public interface ApiContext { InvitationService getInvitationService(); RemoteFetcher getRemoteFetcher(); MailService getMailService(); + MessageSource getMessageSource(); } diff --git a/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java b/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java index ff0554386..1ad80ba04 100644 --- a/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java +++ b/dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java @@ -3,6 +3,7 @@ package eu.eudat.services; import eu.eudat.proxy.fetching.RemoteFetcher; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; +import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; /** @@ -16,6 +17,7 @@ public class ApiContextImpl implements ApiContext{ private RemoteFetcher remoteFetcher; private InvitationService invitationService; private MailService mailService; + private MessageSource messageSource; @Autowired public void setDatabaseRepository(DatabaseRepository databaseRepository) { @@ -67,4 +69,13 @@ public class ApiContextImpl implements ApiContext{ this.mailService = mailService; } + @Override + public MessageSource getMessageSource() { + return messageSource; + } + + @Autowired + public void setMessageSource(MessageSource messageSource) { + this.messageSource = messageSource; + } } diff --git a/dmp-backend/src/main/resources/messages.properties b/dmp-backend/src/main/resources/messages.properties index 3c109db7e..b8d8b0f14 100644 --- a/dmp-backend/src/main/resources/messages.properties +++ b/dmp-backend/src/main/resources/messages.properties @@ -4,4 +4,5 @@ projectTableRequest.periodStart.overlapping = Period Start cannot overlap Period projectTableRequest.offset.negative=table offset cannot be negative projectTableRequest.length.negative=table length cannot be negative datasetprofile.label.null = Dataset Profile Label cannot be null -project.startDate.overlapping = Period Start cannot overlap Period End \ No newline at end of file +project.startDate.overlapping = Period Start cannot overlap Period +dataset.public = Dataset Has Been Made Public \ No newline at end of file diff --git a/dmp-backend/src/main/resources/messages_el.properties b/dmp-backend/src/main/resources/messages_el.properties index d37feed71..e79ab0728 100644 --- a/dmp-backend/src/main/resources/messages_el.properties +++ b/dmp-backend/src/main/resources/messages_el.properties @@ -1,2 +1,8 @@ -datamanagementplanrequest.length.negative=Το πληθος των σειρων στο table δεν μπορει να ειναι αρνητικο -datamanagementplanrequest.offset.negative=Το offset των τιμων δεν μπορει να ειναι αρνητικο \ No newline at end of file +datamanagementplanrequest.length.negative= Το μέγεθος του table δεν μπορει να ειναι αρνητικο +datamanagementplanrequest.offset.negative= Το offset του table δεν μπορει να ειναι αρνητικο +projectTableRequest.periodStart.overlapping = Η Αρχικη Περιοδος δεν μπορει να ειναι Μεγαλυτερη της τελικης +projectTableRequest.offset.negative= Το offset του table δεν μπορει να ειναι αρνητικο +projectTableRequest.length.negative= Το μέγεθος του table δεν μπορει να ειναι αρνητικο +datasetprofile.label.null = Το ονομα του ορισμου ενος Dataset δεν μπορει να ειναι κενο +project.startDate.overlapping = Η Αρχικη Περιοδος δεν μπορει να ειναι Μεγαλυτερη της τελικης +dataset.public = Το Dataset δημοσιοποιηθηκε σε ολους \ No newline at end of file diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.ts b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.ts index d1472b899..f12fa47e8 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.ts +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.ts @@ -19,7 +19,7 @@ import { RuleStyle } from '../../entities/common/rulestyle'; encapsulation: ViewEncapsulation.None }) -export class DynamicFormFieldComponent { +export class DynamicFormFieldComponent implements OnInit{ @Input() field: Field; @Input() form: FormGroup; @Input() pathName:string; @@ -27,6 +27,11 @@ export class DynamicFormFieldComponent { constructor(private route: ActivatedRoute,private visibilityRulesService:VisibilityRulesService) { } + ngOnInit(){ + this.form.get('value').valueChanges.subscribe(item => { + this.visibilityRulesService.updateValueAndVisibility(this.field.id) + }) + } ngOnChanges(changeRecord) { diff --git a/dmp-frontend/src/app/invitation/invitation.component.ts b/dmp-frontend/src/app/invitation/invitation.component.ts index 5e98b9935..b63c2f880 100644 --- a/dmp-frontend/src/app/invitation/invitation.component.ts +++ b/dmp-frontend/src/app/invitation/invitation.component.ts @@ -27,7 +27,7 @@ export class InvitationComponent implements OnInit { private invitationService: InvitationService, private route: ActivatedRoute, public router: Router, - public dialogRef: MatDialogRef, + public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any ) { } @@ -40,7 +40,7 @@ export class InvitationComponent implements OnInit { send(value: any) { this.invitationService.inviteUsers(this.formGroup.value).subscribe( - null,null,()=>this.dialogRef.close() + null, null, () => this.dialogRef.close() ); } diff --git a/dmp-frontend/src/app/visibility-rules/models/VisibilityRule.ts b/dmp-frontend/src/app/visibility-rules/models/VisibilityRule.ts index 81ee45c0f..56051bd71 100644 --- a/dmp-frontend/src/app/visibility-rules/models/VisibilityRule.ts +++ b/dmp-frontend/src/app/visibility-rules/models/VisibilityRule.ts @@ -1,5 +1,5 @@ import { VisibilityRuleSource } from './VisibilityRuleSource'; -export class VisibilityRule{ - public targetControlId:string; - public sourceVisibilityRules:Array +export class VisibilityRule { + public targetControlId: string; + public sourceVisibilityRules: Array } \ No newline at end of file diff --git a/dmp-frontend/src/app/visibility-rules/visibility-rules.service.ts b/dmp-frontend/src/app/visibility-rules/visibility-rules.service.ts index c77a8dc46..075bfb147 100644 --- a/dmp-frontend/src/app/visibility-rules/visibility-rules.service.ts +++ b/dmp-frontend/src/app/visibility-rules/visibility-rules.service.ts @@ -9,33 +9,43 @@ export class VisibilityRulesService { public formGroup: FormGroup; public visibilityRuleContext: VisibilityRulesContext; public fieldsPathMemory: any = {}; + private elementVisibilityMap = new Map(); public isElementVisible(pathKey: string, id: string) { if (!this.fieldsPathMemory[id] && pathKey) this.fieldsPathMemory[id] = pathKey; - let visibilityRule = this.visibilityRuleContext.getRulesFromKey(id); - if (!visibilityRule) return true; - if (this.checkElementVisibility(visibilityRule)) { + if (this.checkElementVisibility(id)) { return true } else { this.clearValues(pathKey) - // if (pathKey && this.formGroup.get(pathKey + '.value')) this.formGroup.get(pathKey + '.value').patchValue(null) return false; } } - public checkElementVisibility(visibilityRule: VisibilityRule): boolean { - let sourceVisibilityRules = visibilityRule.sourceVisibilityRules; - for (let i = 0; i < sourceVisibilityRules.length; i++) { - let sourceVisibilityRule = sourceVisibilityRules[i]; - if (!this.formGroup.get(this.fieldsPathMemory[sourceVisibilityRule.sourceControlId] + '.value')) return false; //TODO - if (sourceVisibilityRule.sourceControlValue != '' + this.formGroup.get(this.fieldsPathMemory[sourceVisibilityRule.sourceControlId] + '.value').value) return false; - } - return true; + public checkElementVisibility(id: string): boolean { + if (!this.elementVisibilityMap.has(id) || this.elementVisibilityMap.get(id)) return true; + else return false; } public buildVisibilityRules(item: Array) { this.visibilityRuleContext = new VisibilityRulesContext(); this.visibilityRuleContext.buildVisibilityRuleContext(item); + this.visibilityRuleContext.rules.forEach(item => this.evaluateVisibility(item)) + } + + public updateValueAndVisibility(id: string) { + let visibilityRules = this.visibilityRuleContext.rules.filter(item => item.sourceVisibilityRules.filter(source => source.sourceControlId === id).length > 0); + visibilityRules.forEach(item => this.evaluateVisibility(item)) + } + + private evaluateVisibility(visibilityRule: VisibilityRule) { + for (let i = 0; i < visibilityRule.sourceVisibilityRules.length; i++) { + let pathKey = this.fieldsPathMemory[visibilityRule.sourceVisibilityRules[i].sourceControlId]; + if (this.formGroup.get(pathKey + '.value') && this.formGroup.get(pathKey + '.value').value != '' + visibilityRule.sourceVisibilityRules[i].sourceControlValue) { + this.elementVisibilityMap.set(visibilityRule.targetControlId, false) + } else { + this.elementVisibilityMap.set(visibilityRule.targetControlId, true) + } + } } private getParentPath(parentId: string): string { @@ -44,10 +54,10 @@ export class VisibilityRulesService { private clearValues(pathKey) { if (pathKey && this.formGroup.get(pathKey + '.value')) this.formGroup.get(pathKey + '.value').patchValue(null) - if (pathKey && this.formGroup.get(pathKey)["controls"].fields){ + if (pathKey && this.formGroup.get(pathKey)["controls"].fields) { for (var i = 0; i < this.formGroup.get(pathKey)["controls"].fields.length; i++) - this.clearValues(pathKey+'.fields.'+i); - } - + this.clearValues(pathKey + '.fields.' + i); + } + } } \ No newline at end of file