Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/unable to save notes(comments) #428

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
-->
<span class="comments-status pull-left"
data-toggle="popover"
data-ng-class="case.comment ? 'present' : 'absent'"
data-content="{{case.comment && '<p>' + case.comment + '</p>' || !case.model.comment && '<span>Click to update this case note</span>'}}"
data-ng-class="case.comment ? 'present' : case.comparator.comment ? 'present' : 'absent'"
data-content="{{case.comment && '<p>' + case.comment + '</p>' || case.comparator.comment && '<p>' + case.comparator.comment + '</p>' || !case.model.comment && '<span>Click to update this case note</span>'}}"
data-html="true" data-trigger="hover"
data-aet-included-comment-popover
data-ng-click="urlView.displayCommentModal(case)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ define(['angularAMD'], function (angularAMD) {
'use strict';
angularAMD.controller('noteModalController', NoteModalController);

function NoteModalController($scope, $uibModalInstance, model, viewMode,
notesService) {
function NoteModalController($scope, $uibModalInstance, model, viewMode, viewModeService,
notesService, $stateParams) {

var vm = this;
init();

Expand All @@ -33,12 +34,21 @@ define(['angularAMD'], function (angularAMD) {
vm.cancelNote = cancelNote;
vm.deleteNote = deleteNote;
vm.viewMode = viewMode;
vm.noteText = model.comment ? model.comment : '';
vm.noteText = getComment(viewMode);
vm.model = model;
}

function getComment(viewMode) {
if (viewMode === viewModeService.COMPARATOR) {
return model.comparator.comment ? model.comparator.comment : '';
}
else {
return model.comment ? model.comment : '';
}
}

function updateNote() {
notesService.updateNote(vm.model, vm.noteText);
notesService.updateNote(vm, $stateParams);
$uibModalInstance.close();
}

Expand Down
35 changes: 33 additions & 2 deletions report/src/main/webapp/app/services/metadata.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ define(['angularAMD', 'metadataCacheService', 'metadataEndpointService'],
getTest: getTest,
getUrl: getUrl,
getStep: getStep,
getStepComparator: getStepComparator,
notifyMetadataChanged: notifyMetadataChanged,
updateComment: updateComment,
saveChangesLocally: saveChangesLocally,
discardLocalChanges: discardLocalChanges,
commitLocalChanges: commitLocalChanges
Expand Down Expand Up @@ -89,10 +91,38 @@ define(['angularAMD', 'metadataCacheService', 'metadataEndpointService'],
return step;
}

function getStepByStepName(testName, urlName, stepName) {
var step = null;
var url = getUrl(testName, urlName);
for (var stepNr = 0; stepNr < url.steps.length; stepNr++) {
if (url.steps[stepNr].name === stepName) {
step = url.steps[stepNr];
}
}
return step;
}

function getStepComparator(testName, urlName, stepName, comparatorIndex) {
var step = getStepByStepName(testName, urlName, stepName);
var comparator = null;
if (step !== null && step.comparators[comparatorIndex] !== null ) {
comparator = step.comparators[comparatorIndex];
}
return comparator
}

function notifyMetadataChanged() {
$rootScope.$emit('metadata:changed');
}

function updateComment(vm, param) {
var caseName = vm.model.displayName.split(" ")[0];
var testName = param.test;
var comparatorIndex = vm.model.index;
var comparator = getStepComparator(testName, param.url, caseName, comparatorIndex);
comparator.comment = vm.noteText;
}

function saveChangesLocally() {
metadataCacheService.put(suite);
}
Expand Down Expand Up @@ -251,7 +281,7 @@ define(['angularAMD', 'metadataCacheService', 'metadataEndpointService'],

function hasStepComparatorAcceptedChanges(comparator) {
return comparator && comparator.stepResult &&
comparator.stepResult.rebaseable &&
comparator.stepResult.rebaseable &&
comparator.stepResult.status === 'REBASED';
}

Expand Down Expand Up @@ -354,4 +384,5 @@ define(['angularAMD', 'metadataCacheService', 'metadataEndpointService'],
}
}
}
});
}
);
4 changes: 4 additions & 0 deletions report/src/main/webapp/app/services/metadataAccess.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ define(['angularAMD', 'metadataService'], function (angularAMD) {
getUrl: getUrl,
getTestUrls: getTestUrls,
getStep: getStep,
getStepComparator:getStepComparator,
getUrlSteps: getUrlSteps
};

Expand Down Expand Up @@ -64,5 +65,8 @@ define(['angularAMD', 'metadataService'], function (angularAMD) {
function getStep(testName, urlName, stepIndex) {
return metadataService.getStep(testName, urlName, stepIndex);
}
function getStepComparator(testName, urlName, stepIndex) {
return metadataService.getStepComparator(testName, urlName, stepIndex);
}
}
});
26 changes: 22 additions & 4 deletions report/src/main/webapp/app/services/notes.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ define(['angularAMD', 'metadataService'], function (angularAMD) {
/**
* Service responsible adding and removing notes from metadata.
*/
function NotesService(metadataService) {
function NotesService(metadataService, viewModeService) {
var service = {
updateNote: updateNote,
deleteNote: deleteNote,
Expand All @@ -31,16 +31,34 @@ define(['angularAMD', 'metadataService'], function (angularAMD) {

return service;

function updateNote(object, text) {
object.comment = text;
function updateNote(vm, param) {
if (vm.viewMode === viewModeService.COMPARATOR) {
updateComparatorComment(vm, param);
} else {
updateUrlComment(vm);
}
updateUnsavedNotesFlag();
metadataService.saveChangesLocally();
metadataService.notifyMetadataChanged();
}

function updateUrlComment(vm) {
vm.model.comment = vm.noteText;
}

function updateComparatorComment(vm, param) {
metadataService.updateComment(vm, param);
}

function deleteNote(object) {
var text = object.comment;
delete object.comment;
if (object.comment) {
text = object.comment;
delete object.comment;
} else {
text = object.comparator.comment;
delete object.comparator.comment;
}
updateUnsavedNotesFlag();
metadataService.saveChangesLocally();
metadataService.notifyMetadataChanged();
Expand Down