Personal note: client rework

This commit is contained in:
FinnStutzenstein 2017-05-24 08:38:27 +02:00 committed by Norman Jäckel
parent 91d365e386
commit c80b0abc82
4 changed files with 81 additions and 35 deletions

View File

@ -805,12 +805,13 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
'MotionPartialContentProvider',
'PdfCreate',
'PDFLayout',
'PersonalNoteManager',
'Messaging',
'FileSaver',
function ($http, $q, operator, Config, gettextCatalog, MotionChangeRecommendation, HTMLValidizer,
PdfMakeConverter, MotionContentProvider, MotionCatalogContentProvider, PdfMakeDocumentProvider,
PollContentProvider, PdfMakeBallotPaperProvider, MotionPartialContentProvider, PdfCreate,
PDFLayout, Messaging, FileSaver) {
PDFLayout, PersonalNoteManager, Messaging, FileSaver) {
return {
getDocumentProvider: function (motions, params, singleMotion) {
params = _.clone(params || {}); // Clone this to avoid sideeffects.
@ -941,9 +942,7 @@ angular.module('OpenSlidesApp.motions.pdf', ['OpenSlidesApp.core.pdf'])
PdfCreate.download(documentProvider.getDocument(), filename);
},
exportPersonalNote: function (motion, filename) {
var personalNote = _.find(motion.personal_notes, function (note) {
return note.user_id === operator.user.id;
});
var personalNote = PersonalNoteManager.getNote(motion);
var content = [{
heading: gettextCatalog.getString('Personal note'),
text: personalNote ? personalNote.note : '',

View File

@ -873,9 +873,11 @@ angular.module('OpenSlidesApp.motions.site', [
'osTableSort',
'MotionExportForm',
'MotionPdfExport',
'PersonalNoteManager',
function($scope, $state, $http, gettext, gettextCatalog, operator, ngDialog, MotionForm, Motion,
MotionComment, Category, Config, Tag, Workflow, User, Agenda, MotionBlock, Projector,
ProjectionDefault, osTableFilter, osTableSort, MotionExportForm, MotionPdfExport) {
ProjectionDefault, osTableFilter, osTableSort, MotionExportForm, MotionPdfExport,
PersonalNoteManager) {
Category.bindAll({}, $scope, 'categories');
MotionBlock.bindAll({}, $scope, 'motionBlocks');
Tag.bindAll({}, $scope, 'tags');
@ -895,9 +897,7 @@ angular.module('OpenSlidesApp.motions.site', [
}, function () {
$scope.motions = Motion.getAll();
_.forEach($scope.motions, function (motion) {
motion.personalNote = _.find(motion.personal_notes, function (note) {
return note.user_id === operator.user.id;
});
motion.personalNote = PersonalNoteManager.getNote(motion);
// For filtering, we cannot filter for .personalNote.star
motion.star = motion.personalNote ? motion.personalNote.star : false;
});
@ -1089,9 +1089,7 @@ angular.module('OpenSlidesApp.motions.site', [
} else {
motion.personalNote = {star: true};
}
$http.put('/rest/motions/motion/' + motion.id + '/set_personal_note/',
motion.personalNote
);
PersonalNoteManager.saveNote(motion, motion.personalNote);
};
// open new/edit dialog
@ -1191,12 +1189,13 @@ angular.module('OpenSlidesApp.motions.site', [
'ProjectionDefault',
'MotionBlock',
'MotionPdfExport',
'PersonalNoteManager',
'EditingWarning',
function($scope, $http, $timeout, operator, ngDialog, gettextCatalog, MotionForm,
ChangeRecommmendationCreate, ChangeRecommmendationView, MotionChangeRecommendation,
Motion, MotionComment, Category, Mediafile, Tag, User, Workflow, Config, motionId, MotionInlineEditing,
MotionCommentsInlineEditing, Projector, ProjectionDefault, MotionBlock, MotionPdfExport,
EditingWarning) {
PersonalNoteManager, EditingWarning) {
var motion = Motion.get(motionId);
Category.bindAll({}, $scope, 'categories');
Mediafile.bindAll({}, $scope, 'mediafiles');
@ -1231,9 +1230,7 @@ angular.module('OpenSlidesApp.motions.site', [
}, function () {
$scope.motion = Motion.get(motionId);
MotionComment.populateFields($scope.motion);
$scope.motion.personalNote = _.find($scope.motion.personal_notes, function (note) {
return note.user_id === operator.user.id;
});
$scope.motion.personalNote = PersonalNoteManager.getNote($scope.motion);
});
$scope.projectionModes = [
{mode: 'original',
@ -1462,21 +1459,7 @@ angular.module('OpenSlidesApp.motions.site', [
} else {
$scope.motion.personalNote = {star: true};
}
$http.put('/rest/motions/motion/' + $scope.motion.id + '/set_personal_note/',
$scope.motion.personalNote
);
};
// personal note
$scope.toggleStar = function () {
if ($scope.motion.personalNote) {
$scope.motion.personalNote.star = !$scope.motion.personalNote.star;
} else {
$scope.motion.personalNote = {star: true};
}
$http.put('/rest/motions/motion/' + $scope.motion.id + '/set_personal_note/',
$scope.motion.personalNote
);
PersonalNoteManager.saveNote($scope.motion, $scope.motion.personalNote);
};
// Inline editing functions
@ -1516,9 +1499,7 @@ angular.module('OpenSlidesApp.motions.site', [
} else {
motion.personalNote = {note: obj.editor.getData()};
}
$http.put('/rest/motions/motion/' + $scope.motion.id + '/set_personal_note/',
motion.personalNote
);
PersonalNoteManager.saveNote(motion, motion.personalNote);
obj.revert();
obj.disable();
return true; // Do not update the motion via patch request.

View File

@ -131,9 +131,10 @@ angular.module('OpenSlidesApp.users', [])
'$http',
'DS',
function($http, DS) {
var name = 'users/group';
var permissions;
return DS.defineResource({
name: 'users/group',
name: name,
permissions: permissions,
// TODO (Issue 2862): Do not query the permissions from server. They should be included
// in the startup data. Then remove 'permission' injection from group list controller.
@ -150,13 +151,31 @@ angular.module('OpenSlidesApp.users', [])
}
])
.factory('PersonalNote', [
'DS',
function (DS) {
var name = 'users/personal-note';
return DS.defineResource({
name: name,
relations: {
hasOne: {
'users/user': {
localField: 'user',
localKey: 'user_id',
}
}
}
});
}
])
.run([
'User',
'Group',
'PersonalNote',
function(User, Group) {}
])
// Mark strings for translation in JavaScript.
.config([
'gettext',

View File

@ -203,6 +203,53 @@ angular.module('OpenSlidesApp.users.site', [
}
])
.factory('PersonalNoteManager', [
'PersonalNote',
'operator',
function (PersonalNote, operator) {
var _getPersonalNoteObject = function (resourceName) {
var personalNote = _.find(PersonalNote.getAll(), function (pn) {
return pn.user_id === operator.user.id;
});
if (!personalNote) {
personalNote = {
notes: {},
};
}
if (!personalNote.notes[resourceName]) {
personalNote.notes[resourceName] = {};
}
return personalNote;
};
var get = function (resourceName, id) {
return _getPersonalNoteObject(resourceName).notes[resourceName][id];
};
var save = function (resourceName, id, note) {
var personalNote = _getPersonalNoteObject(resourceName);
personalNote.notes[resourceName][id] = note;
if (personalNote.id) {
return PersonalNote.save(personalNote);
} else {
return PersonalNote.create(personalNote);
}
};
return {
getNote: function (obj) {
if (typeof obj.getResourceName === 'undefined') {
throw 'The Object has to be a js data model!';
}
return get(obj.getResourceName(), obj.id);
},
saveNote: function (obj, note) {
if (typeof obj.getResourceName === 'undefined') {
throw 'The Object has to be a js data model!';
}
return save(obj.getResourceName(), obj.id, note);
},
};
}
])
// Service for generic assignment form (create and update)
.factory('UserForm', [
'$http',