Skip to content

Commit

Permalink
Merge pull request #184 from TAMULib/product-sprint6-staging
Browse files Browse the repository at this point in the history
Product sprint6 staging
  • Loading branch information
jcreel committed Sep 18, 2020
2 parents 4ff0365 + 30fa767 commit 587b863
Show file tree
Hide file tree
Showing 15 changed files with 661 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ app.controller('ServiceDetailFeatureProposalListController', function ($controll
}, 500);
});

if (!$scope.isAnonymous()) {
UserRepo.getUser().then(function (res) {
var apiRes = angular.fromJson(res.body);
if (apiRes.meta.status === 'SUCCESS') {
$scope.user = apiRes.payload.User;
$scope.hasVoted = function (fp) {
return fp.voters.map(function(v) { return v.id; }).indexOf($scope.user.id) >= 0;
};
}
});
}
UserRepo.ready().then(function () {
if (!$scope.isAnonymous()) {
UserRepo.getUser().then(function (res) {
var apiRes = angular.fromJson(res.body);
if (apiRes.meta.status === 'SUCCESS') {
$scope.user = apiRes.payload.User;
$scope.hasVoted = function (fp) {
return fp.voters.map(function(v) { return v.id; }).indexOf($scope.user.id) >= 0;
};
}
});
}
});

$scope.isVotingOpen = function (featureProposal) {
return !$scope.isAnonymous() && featureProposal.state === FeatureProposalState.ACTIVE.value;
Expand All @@ -58,4 +60,4 @@ app.controller('ServiceDetailFeatureProposalListController', function ($controll
});
};

});
});
53 changes: 38 additions & 15 deletions app/repo/ideaRepo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory, UserService) {

var ideaRepo = this;

Expand Down Expand Up @@ -59,23 +59,46 @@ app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
}
};

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});
var canAccess = function () {
var user = UserService.getCurrentUser();
var access = false;

WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});
if (user.role === undefined || user.role === null || user.anonymous) {
access = false;
}
else if (user.role === 'ROLE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_MANAGER') {
access = true;
}

return access;
};

UserService.userReady().then(function () {
if (canAccess()) {

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
});
}
});

return ideaRepo;

});
});
12 changes: 7 additions & 5 deletions app/repo/userRepo.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
app.repo("UserRepo", function UserRepo(WsApi) {

this.getUser = function () {
return WsApi.fetch(this.mapping.getUser);
};
var userRepo = this;

return this;
userRepo.getUser = function () {
return WsApi.fetch(this.mapping.getUser);
};

});
return userRepo;

});
11 changes: 1 addition & 10 deletions app/services/productService.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@ app.service('ProductService', function ($q, WsApi) {
angular.extend(apiMapping.Product.submitFeatureProposal, {
'data': fp
});
return $q(function (resolve, reject) {
WsApi.fetch(apiMapping.Product.submitFeatureProposal).then(function (response) {
var apiRes = angular.fromJson(response.body);
if (apiRes.meta.status === 'SUCCESS') {
resolve();
} else {
reject();
}
});
});
return WsApi.fetch(apiMapping.Product.submitFeatureProposal);
};

});
1 change: 0 additions & 1 deletion app/views/directives/featureProposal.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<div class="row">
<div class="lead col-md-8">
<span>{{featureProposal.title}}</span>
<span> ({{featureProposal.state | featureProposalState}})</span>
</div>
<div class="lead col-md-4" ng-if="!isAnonymous()">
<span ng-if="hasVoted(featureProposal)" class="glyphicon glyphicon-ok text-success pull-right"></span>
Expand Down
3 changes: 2 additions & 1 deletion app/views/request/request.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h3>What kind of feedback would you like to provide today?</h3>
</div>
</div>
<div class="col-sm-8 col-sm-offset-2" ng-show="type">
<alerts seconds="45" channels="services/feature,services/issue" types="SUCCESS"></alerts>
<center>
<h3>Please provide a title and a description for
<span>{{type === 'FEATURE' ? 'feature or idea' : 'issue or bug'}}</span>.</h3>
Expand Down Expand Up @@ -61,4 +62,4 @@ <h3>Please provide a title and a description for
</form>
</div>
</div>
</div>
</div>
4 changes: 4 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ module.exports = function (config) {

'app/repo/**/*.js',

'app/views/**/*.html',

'tests/core/**/*.js',

'tests/mocks/**/*.js',

'tests/unit/**/*.js'
Expand Down
112 changes: 112 additions & 0 deletions tests/core/mocks/mockAbstractCoreModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
var mockModel = function (modelName, $q, mockDataObj) {
var model = {};
var shadow = {};
var combinationOperation = "";

model.isDirty = false;
model.isValid = false;

model.mock = function (toMock) {
if (typeof toMock === "object") {
var keys = Object.keys(toMock);
for (var i in keys) {
model[keys[i]] = toMock[keys[i]];
}
} else if (toMock === undefined || toMock === null) {
model = null;
}
};

model.mockShadow = function (toMock) {
shadow = toMock;
};

model.acceptPendingUpdate = function () {
};

model.acceptPendingDelete = function () {
};

model.before = function () {
};

model.clearListens = function () {
var payload = {};
return payloadPromise($q.defer(), payload);
};

model.clearValidationResults = function () {
};

model.delete = function () {
return payloadPromise($q.defer(), true);
};

model.dirty = function (boolean) {
if (boolean !== undefined) {
model.isDirty = boolean;
}

return model.isDirty;
};

model.enableMergeCombinationOperation = function () {
combinationOperation = "merge";
};

model.enableExtendCombinationOperation = function () {
combinationOperation = "extend";
};

model.fetch = function () {
return payloadPromise($q.defer(), mockDataObj);
};

model.getCombinationOperation = function () {
return combinationOperation;
};

model.getEntityName = function () {
return modelName;
};

model.getValidations = function () {
return null;
};

model.init = function (data, apiMapping) {
};

model.listen = function () {
};

model.ready = function () {
var defer = $q.defer();
defer.resolve();
return defer.promise;
};

model.refresh = function () {
angular.extend(model, shadow);
};

model.reload = function () {
var defer = $q.defer();
defer.resolve(model);
return defer.promise;
};

model.save = function () {
return payloadPromise($q.defer(), true);
};

model._syncShadow = function () {
model.isDirty = false;
shadow = angular.copy(model);
};

model.mock(mockDataObj);
model._syncShadow();

return model;
};
Loading

0 comments on commit 587b863

Please sign in to comment.