From 43831fa81df18aeffc28b1afc3df2dc9c0ce1403 Mon Sep 17 00:00:00 2001 From: coni2k Date: Sat, 11 Jun 2016 16:32:43 +0200 Subject: [PATCH] 0.56.0 This closes #63 and closes #64 --- .../UserElementFieldIndexTests.cs | 2 +- .../UserResourcePoolTests.cs | 2 +- BusinessObjects/Models/ElementField.cs | 25 +++--- BusinessObjects/Models/ResourcePool.cs | 11 --- BusinessObjects/Models/UserElementField.cs | 4 +- CHANGELOG.md | 7 ++ SolutionItems/Documents/Todo.md | 1 + SolutionItems/Properties/AssemblyInfo.cs | 2 +- ngClient/_system/js/app/config/route.js | 4 +- .../_system/js/app/entities/ElementField.js | 2 + .../_system/js/app/factories/dataContext.js | 16 ++-- .../js/app/factories/resourcePoolFactory.js | 76 +++++++++++++++++-- .../resourcePool/resourcePoolManage.html | 6 ++ ngClient/default.aspx | 2 +- 14 files changed, 110 insertions(+), 50 deletions(-) diff --git a/BusinessObjects.Tests/UserElementFieldIndexTests.cs b/BusinessObjects.Tests/UserElementFieldIndexTests.cs index 714c54c84..fd90ada95 100644 --- a/BusinessObjects.Tests/UserElementFieldIndexTests.cs +++ b/BusinessObjects.Tests/UserElementFieldIndexTests.cs @@ -17,7 +17,7 @@ public void NewUserElementFieldIndex_ShouldCreate() .AddElement("Element") .AddField("Field", ElementFieldDataType.Boolean, true) .EnableIndex(ElementFieldIndexSortType.HighestToLowest) - .AddUserRating(user, 0); + .AddUserRating(0); } } } diff --git a/BusinessObjects.Tests/UserResourcePoolTests.cs b/BusinessObjects.Tests/UserResourcePoolTests.cs index aae333a94..017aa6123 100644 --- a/BusinessObjects.Tests/UserResourcePoolTests.cs +++ b/BusinessObjects.Tests/UserResourcePoolTests.cs @@ -11,7 +11,7 @@ public void NewUserResourcePool_ShouldCreate() { var user = new User("User", "user@email.com"); var resourcePool = new ResourcePool(user, "CMRP") - .AddUserResourcePool(user, 0); + .AddUserResourcePool(0); } } } diff --git a/BusinessObjects/Models/ElementField.cs b/BusinessObjects/Models/ElementField.cs index 72c0b5a83..c8c88c28a 100644 --- a/BusinessObjects/Models/ElementField.cs +++ b/BusinessObjects/Models/ElementField.cs @@ -86,33 +86,23 @@ public ElementField(Element element, string name, ElementFieldDataType fieldType #region - Methods - - public UserElementField AddUserRating(User user, decimal rating) + public UserElementField AddUserRating(decimal rating) { // TODO Validation? - var userRating = new UserElementField(user, this, rating); - user.UserElementFieldSet.Add(userRating); + + var userRating = new UserElementField(this, rating); UserElementFieldSet.Add(userRating); return userRating; } public ElementField EnableIndex() { - ValidateEnableIndex(); - - IndexEnabled = true; - IndexCalculationType = (byte)ElementFieldIndexCalculationType.Aggressive; - IndexSortType = (byte)ElementFieldIndexSortType.HighestToLowest; - return this; + return EnableIndex(ElementFieldIndexCalculationType.Aggressive, ElementFieldIndexSortType.HighestToLowest); } public ElementField EnableIndex(ElementFieldIndexSortType indexSortType) { - ValidateEnableIndex(); - - IndexEnabled = true; - IndexCalculationType = (byte)ElementFieldIndexCalculationType.Aggressive; - IndexSortType = (byte)indexSortType; - return this; + return EnableIndex(ElementFieldIndexCalculationType.Aggressive, indexSortType); } public ElementField EnableIndex(ElementFieldIndexCalculationType calculationType, ElementFieldIndexSortType indexSortType) @@ -122,9 +112,14 @@ public ElementField EnableIndex(ElementFieldIndexCalculationType calculationType IndexEnabled = true; IndexCalculationType = (byte)calculationType; IndexSortType = (byte)indexSortType; + + AddUserRating(50); + return this; } + // TODO Where is DisableIndex my dear?! / SH - 11 Jun. '16 + void ValidateEnableIndex() { if (DataType == (byte)ElementFieldDataType.String diff --git a/BusinessObjects/Models/ResourcePool.cs b/BusinessObjects/Models/ResourcePool.cs index 3314aa26a..ad57a83bb 100644 --- a/BusinessObjects/Models/ResourcePool.cs +++ b/BusinessObjects/Models/ResourcePool.cs @@ -90,17 +90,6 @@ public UserResourcePool AddUserResourcePool(decimal rate) return userResourcePool; } - [Obsolete("Try to switch to the method without user variable")] - public UserResourcePool AddUserResourcePool(User user, decimal rate) - { - // Todo Validation? - // var userResourcePool = new UserResourcePool(user, this, rate); - var userResourcePool = new UserResourcePool(this, rate); - user.UserResourcePoolSet.Add(userResourcePool); - UserResourcePoolSet.Add(userResourcePool); - return userResourcePool; - } - #endregion } } diff --git a/BusinessObjects/Models/UserElementField.cs b/BusinessObjects/Models/UserElementField.cs index 23e1363f5..204f31b09 100644 --- a/BusinessObjects/Models/UserElementField.cs +++ b/BusinessObjects/Models/UserElementField.cs @@ -12,13 +12,11 @@ public class UserElementField : BaseEntity public UserElementField() { } - public UserElementField(User user, ElementField elementField, decimal rating) + public UserElementField(ElementField elementField, decimal rating) : this() { - Validations.ArgumentNullOrDefault(user, "user"); Validations.ArgumentNullOrDefault(elementField, "elementField"); - User = user; ElementField = elementField; Rating = rating; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9444f24fe..fa9638ee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ### Changelog +**0.56.0** + +* resourcePoolManage - Field rating edit +https://github.com/forCrowd/WealthEconomy/issues/64 +* Find keep alive service +https://github.com/forCrowd/WealthEconomy/issues/63 + **0.55.1** * resourcePoolEditor.js - getResourcePoolExpanded - resourcePool undefined check was added diff --git a/SolutionItems/Documents/Todo.md b/SolutionItems/Documents/Todo.md index be82eaf32..c750b3d5a 100644 --- a/SolutionItems/Documents/Todo.md +++ b/SolutionItems/Documents/Todo.md @@ -5,6 +5,7 @@ * content for editor? new content or new resourcepool - content in a content? or page as a new entity? * route update (_system/) * application manager - allows admin to update appSettings & restarts the app? +* 360 reasons to destroy - https://t.co/BHdHwjfSfR * expand('User' - brings all user info ?!?!? http://stackoverflow.com/questions/10781309/asp-net-mvc-4-webapi-manually-handle-odata-queries diff --git a/SolutionItems/Properties/AssemblyInfo.cs b/SolutionItems/Properties/AssemblyInfo.cs index 1ac27768f..28ea00a40 100644 --- a/SolutionItems/Properties/AssemblyInfo.cs +++ b/SolutionItems/Properties/AssemblyInfo.cs @@ -30,5 +30,5 @@ // // AssemblyFileVersion is not in use for the moment // -[assembly: AssemblyVersion("0.55.1")] +[assembly: AssemblyVersion("0.56.0")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/ngClient/_system/js/app/config/route.js b/ngClient/_system/js/app/config/route.js index fb556db9b..4c8970688 100644 --- a/ngClient/_system/js/app/config/route.js +++ b/ngClient/_system/js/app/config/route.js @@ -45,8 +45,8 @@ /* User */ .when('/:userName', { title: 'Profile', templateUrl: '/_system/views/account/profile.html?v=0.51.0', resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) - .when('/:userName/new', { title: 'New CMRP', templateUrl: '/_system/views/resourcePool/resourcePoolManage.html?v=0.55.0', resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) - .when('/:userName/:resourcePoolKey/edit', { title: 'Edit CMRP', templateUrl: '/_system/views/resourcePool/resourcePoolManage.html?v=0.55.0', resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) + .when('/:userName/new', { title: 'New CMRP', templateUrl: '/_system/views/resourcePool/resourcePoolManage.html?v=0.56.0', resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) + .when('/:userName/:resourcePoolKey/edit', { title: 'Edit CMRP', templateUrl: '/_system/views/resourcePool/resourcePoolManage.html?v=0.56.0', resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) .when('/:userName/:resourcePoolKey', { title: 'View CMRP', templateUrl: '/_system/views/resourcePool/resourcePoolView.html?v=0.49.0', enableDisqus: true, resolve: { validateAccess: ['dataContext', 'locationHistory', 'logger', '$location', '$q', '$route', validateAccess] } }) /* Otherwise */ diff --git a/ngClient/_system/js/app/entities/ElementField.js b/ngClient/_system/js/app/entities/ElementField.js index 1c1015dc9..497b8c376 100644 --- a/ngClient/_system/js/app/entities/ElementField.js +++ b/ngClient/_system/js/app/entities/ElementField.js @@ -82,6 +82,8 @@ this.IndexCalculationType = value ? 1 : 0; this.IndexSortType = value ? 1 : 0; + $rootScope.$broadcast('ElementField_IndexEnabledChanged', this); + // TODO Complete this block! //// Update related diff --git a/ngClient/_system/js/app/factories/dataContext.js b/ngClient/_system/js/app/factories/dataContext.js index 9187808d0..daffb6c88 100644 --- a/ngClient/_system/js/app/factories/dataContext.js +++ b/ngClient/_system/js/app/factories/dataContext.js @@ -50,6 +50,7 @@ getChangesCount: getChangesCount, getCurrentUser: getCurrentUser, getEntities: getEntities, + getEntityByKey: getEntityByKey, getToken: getToken, getUniqueEmail: getUniqueEmail, getUniqueUserName: getUniqueUserName, @@ -72,9 +73,6 @@ updateResourcePoolRate: updateResourcePoolRate }; - // Event handlers - $rootScope.$on('ElementField_createUserElementCell', createUserElementCell); - _init(); return factory; @@ -163,12 +161,8 @@ .error(handleErrorResult); } - function createEntity(entityType, initialValues) { - return manager.createEntity(entityType, initialValues); - } - - function createUserElementCell(event, userElementCell) { - return createEntity('UserElementCell', userElementCell); + function createEntity(entityType, initialValues, entityState, mergeStrategy) { + return manager.createEntity(entityType, initialValues, entityState, mergeStrategy); } function executeQuery(query) { @@ -207,6 +201,10 @@ return manager.getEntities(entityTypes, entityStates); } + function getEntityByKey(entityType, entityKey) { + return manager.getEntityByKey(entityType, entityKey); + } + // Returns either unauthenticated or logged in user function getCurrentUser(resetPromise) { resetPromise = typeof resetPromise !== 'undefined' ? resetPromise : false; diff --git a/ngClient/_system/js/app/factories/resourcePoolFactory.js b/ngClient/_system/js/app/factories/resourcePoolFactory.js index a57f93c30..647edd8c8 100644 --- a/ngClient/_system/js/app/factories/resourcePoolFactory.js +++ b/ngClient/_system/js/app/factories/resourcePoolFactory.js @@ -24,7 +24,8 @@ removeElement: removeElement, removeElementField: removeElementField, removeElementItem: removeElementItem, - removeResourcePool: removeResourcePool + removeResourcePool: removeResourcePool, + removeUserElementField: removeUserElementField }; var fetchedList = []; var fetchFromServer = true; @@ -34,6 +35,8 @@ fetchedList = []; fetchFromServer = true; }); + $rootScope.$on('ElementField_createUserElementCell', elementField_createUserElementCell); + $rootScope.$on('ElementField_IndexEnabledChanged', elementField_IndexEnabledChanged); return factory; @@ -79,6 +82,18 @@ elementField = dataContext.createEntity('ElementField', elementField); + // Related user element field, if IndexEnabled + if (elementField.IndexEnabled) { + + var userElementField = { + User: elementField.Element.ResourcePool.User, + ElementField: elementField, + Rating: 50 + }; + + dataContext.createEntity('UserElementField', userElementField); + } + // Related cells elementField.Element.ElementItemSet.forEach(function (elementItem) { createElementCell({ @@ -258,6 +273,49 @@ }); } + function elementField_createUserElementCell(event, userElementCell) { + return dataContext.createEntity('UserElementCell', userElementCell); + } + + function elementField_IndexEnabledChanged(event, elementField) { + + if (elementField.Element === null) { + return; + } + + // Add user element field, if IndexEnabled and there is none + if (elementField.IndexEnabled) { + + // Search for an existing entity + var existingKey = [elementField.Element.ResourcePool.User.Id, elementField.Id]; + var existing = dataContext.getEntityByKey('UserElementField', existingKey); + + if (existing !== null) { + + // If it's deleted, restore it + if (existing.entityAspect.entityState.isDeleted()) { + existing.entityAspect.rejectChanges(); + } + + existing.Rating = 50; + + } else { + + var userElementField = { + User: elementField.Element.ResourcePool.User, + ElementField: elementField, + Rating: 50 + }; + + dataContext.createEntity('UserElementField', userElementField); + } + } else { + + // Related user element fields + removeUserElementField(elementField); + } + } + function getResourcePoolExpanded(resourcePoolUniqueKey) { // TODO Validations? @@ -284,7 +342,7 @@ var userNamePredicate = new breeze.Predicate('User.UserName', 'eq', resourcePoolUniqueKey.userName); var resourcePoolKeyPredicate = new breeze.Predicate('Key', 'eq', resourcePoolUniqueKey.resourcePoolKey); - + query = query.where(userNamePredicate.and(resourcePoolKeyPredicate)); // From server or local? @@ -396,10 +454,7 @@ }); // Related user element fields - var userElementFieldSet = elementField.UserElementFieldSet.slice(); - userElementFieldSet.forEach(function (userElementField) { - userElementField.entityAspect.setDeleted(); - }); + removeUserElementField(elementField); elementField.entityAspect.setDeleted(); } @@ -431,5 +486,14 @@ resourcePool.entityAspect.setDeleted(); } + + function removeUserElementField(elementField) { + + // Related user element fields + var userElementFieldSet = elementField.UserElementFieldSet.slice(); + userElementFieldSet.forEach(function (userElementField) { + userElementField.entityAspect.setDeleted(); + }); + } } })(); diff --git a/ngClient/_system/views/resourcePool/resourcePoolManage.html b/ngClient/_system/views/resourcePool/resourcePoolManage.html index 68a5e998a..ce0da37cf 100644 --- a/ngClient/_system/views/resourcePool/resourcePoolManage.html +++ b/ngClient/_system/views/resourcePool/resourcePoolManage.html @@ -237,6 +237,12 @@

+
+ +
+ +
+
diff --git a/ngClient/default.aspx b/ngClient/default.aspx index 2ae6a17db..bbc2338d4 100644 --- a/ngClient/default.aspx +++ b/ngClient/default.aspx @@ -137,7 +137,7 @@ - +