Skip to content

Commit

Permalink
0.56.0
Browse files Browse the repository at this point in the history
This closes #63 and closes #64
  • Loading branch information
coni2k committed Jun 11, 2016
1 parent 26d6124 commit 43831fa
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 50 deletions.
2 changes: 1 addition & 1 deletion BusinessObjects.Tests/UserElementFieldIndexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void NewUserElementFieldIndex_ShouldCreate()
.AddElement("Element")
.AddField("Field", ElementFieldDataType.Boolean, true)
.EnableIndex(ElementFieldIndexSortType.HighestToLowest)
.AddUserRating(user, 0);
.AddUserRating(0);
}
}
}
2 changes: 1 addition & 1 deletion BusinessObjects.Tests/UserResourcePoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
25 changes: 10 additions & 15 deletions BusinessObjects/Models/ElementField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 0 additions & 11 deletions BusinessObjects/Models/ResourcePool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 1 addition & 3 deletions BusinessObjects/Models/UserElementField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions SolutionItems/Documents/Todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion SolutionItems/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
4 changes: 2 additions & 2 deletions ngClient/_system/js/app/config/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions ngClient/_system/js/app/entities/ElementField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions ngClient/_system/js/app/factories/dataContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
getChangesCount: getChangesCount,
getCurrentUser: getCurrentUser,
getEntities: getEntities,
getEntityByKey: getEntityByKey,
getToken: getToken,
getUniqueEmail: getUniqueEmail,
getUniqueUserName: getUniqueUserName,
Expand All @@ -72,9 +73,6 @@
updateResourcePoolRate: updateResourcePoolRate
};

// Event handlers
$rootScope.$on('ElementField_createUserElementCell', createUserElementCell);

_init();

return factory;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
76 changes: 70 additions & 6 deletions ngClient/_system/js/app/factories/resourcePoolFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
removeElement: removeElement,
removeElementField: removeElementField,
removeElementItem: removeElementItem,
removeResourcePool: removeResourcePool
removeResourcePool: removeResourcePool,
removeUserElementField: removeUserElementField
};
var fetchedList = [];
var fetchFromServer = true;
Expand All @@ -34,6 +35,8 @@
fetchedList = [];
fetchFromServer = true;
});
$rootScope.$on('ElementField_createUserElementCell', elementField_createUserElementCell);
$rootScope.$on('ElementField_IndexEnabledChanged', elementField_IndexEnabledChanged);

return factory;

Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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?
Expand All @@ -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?
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
});
}
}
})();
6 changes: 6 additions & 0 deletions ngClient/_system/views/resourcePool/resourcePoolManage.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,12 @@ <h2 data-ng-bind="vm.resourcePool.Name"></h2>
<input id="SortOrder" name="SortOrder" type="text" data-ng-model="vm.elementField.SortOrder" class="form-control" data-z-validate />
</div>
</div>
<div class="form-group" data-ng-if="vm.elementField.IndexEnabled" data-ng-class="{ 'has-error': vm.elementField.UserElementFieldSet[0].entityAspect.getValidationErrors('Rating').length > 0 }">
<label for="Rating" class="control-label col-md-2">Rating</label>
<div class="col-md-10">
<input id="Rating" name="Rating" type="text" data-ng-model="vm.elementField.UserElementFieldSet[0].Rating" class="form-control" data-z-validate data-z-float />
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="RowVersion" name="RowVersion" data-ng-model="vm.elementField.RowVersion" type="hidden">
Expand Down
2 changes: 1 addition & 1 deletion ngClient/default.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
<script src="/_system/js/lib/lib.min.js?v=0.51.0"></script>

<!-- app.js -->
<script src="/_system/js/app/app.min.js?v=0.55.1"></script>
<script src="/_system/js/app/app.min.js?v=0.56.0"></script>

<!-- appSettings.js -->
<script src="/_system/js/appSettings/appSettings.js?v=0.49.0"></script>
Expand Down

0 comments on commit 43831fa

Please sign in to comment.