Collection name to CamelCase (fixes #2983)

This commit is contained in:
FinnStutzenstein 2017-02-21 08:51:31 +01:00 committed by Emanuel Schütze
parent 4d3a45c8fb
commit 5374b2f398
5 changed files with 45 additions and 29 deletions

View File

@ -55,7 +55,9 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users'])
'Projector',
'gettextCatalog',
'gettext',
function($http, DS, Speaker, jsDataModel, Projector, gettextCatalog, gettext) {
'CamelCase',
'EditForm',
function($http, DS, Speaker, jsDataModel, Projector, gettextCatalog, gettext, CamelCase, EditForm) {
var name = 'agenda/item';
return DS.defineResource({
name: name,
@ -68,6 +70,13 @@ angular.module('OpenSlidesApp.agenda', ['OpenSlidesApp.users'])
getContentObject: function () {
return DS.get(this.content_object.collection, this.content_object.id);
},
getContentObjectDetailState: function () {
return CamelCase(this.content_object.collection).replace('/', '.') +
'.detail({id: ' + this.content_object.id + '})';
},
getContentObjectForm: function () {
return EditForm.fromCollectionString(this.content_object.collection);
},
getContentResource: function () {
return DS.definitions[this.content_object.collection];
},

View File

@ -81,7 +81,6 @@ angular.module('OpenSlidesApp.agenda.site', [
'$filter',
'$http',
'$state',
'$injector',
'DS',
'operator',
'ngDialog',
@ -97,7 +96,7 @@ angular.module('OpenSlidesApp.agenda.site', [
'osTableFilter',
'AgendaCsvExport',
'PdfCreate',
function($scope, $filter, $http, $state, $injector, DS, operator, ngDialog, Agenda, TopicForm,
function($scope, $filter, $http, $state, DS, operator, ngDialog, Agenda, TopicForm,
AgendaTree, Projector, ProjectionDefault, AgendaContentProvider, PdfMakeDocumentProvider,
gettextCatalog, gettext, osTableFilter, AgendaCsvExport, PdfCreate) {
// Bind agenda tree to the scope
@ -269,21 +268,8 @@ angular.module('OpenSlidesApp.agenda.site', [
return false;
}
};
$scope.getDetailStatePrefix = function (item) {
var prefix = item.content_object.collection.replace('/','.');
// Hotfix for Issue 2566.
// The changes could be reverted if Issue 2480 is closed.
prefix = prefix.replace('motion-block', 'motionBlock');
return prefix;
};
$scope.edit = function (item) {
var formName = item.content_object.collection.split('/')[1];
// Hotfix for Issue 2566.
// The changes could be reverted if Issue 2480 is closed.
formName = formName.replace('motion-block', 'motionBlock');
formName = formName.charAt(0).toUpperCase() + formName.slice(1) + 'Form';
var form = $injector.get(formName);
ngDialog.open(form.getDialog({id: item.content_object.id}));
ngDialog.open(item.getContentObjectForm().getDialog({id: item.content_object.id}));
};
// export
$scope.pdfExport = function () {

View File

@ -271,7 +271,7 @@
<div>
<!-- ID and title -->
<div>
<a class="title" ui-sref="{{ getDetailStatePrefix(item) }}.detail({id: item.content_object.id})" ng-show="isAllowedToSeeOpenLink(item)">
<a class="title" ui-sref="{{ item.getContentObjectDetailState() }}" ng-show="isAllowedToSeeOpenLink(item)">
{{ item.getListViewTitle() }}
</a>
<span class="title" ng-hide="isAllowedToSeeOpenLink(item)">

View File

@ -682,9 +682,9 @@ angular.module('OpenSlidesApp.core', [
.factory('Projector', [
'DS',
'$http',
'$injector',
'EditForm',
'Config',
function(DS, $http, $injector, Config) {
function(DS, $http, EditForm, Config) {
return DS.defineResource({
name: 'core/projector',
onConflict: 'replace',
@ -716,14 +716,9 @@ angular.module('OpenSlidesApp.core', [
value.name != 'core/countdown' &&
value.name != 'core/projector-message' &&
value.name != 'agenda/current-list-of-speakers' ) {
var formName = value.name.split('/')[1];
// Hotfix for Issue 2566.
// The changes could be reverted if Issue 2480 is closed.
formName = formName.replace('motion-block', 'motionBlock');
formName = formName.charAt(0).toUpperCase() + formName.slice(1) + 'Form';
return_dict = {
form: $injector.get(formName),
id: value.id
form: EditForm.fromCollectionString(value.name),
id: value.id,
};
}
});
@ -953,6 +948,34 @@ angular.module('OpenSlidesApp.core', [
}
])
/* Converts a snake-case string to camelCase. Example:
* 'motion-block-config' -> 'motionBlockConfig' */
.factory('CamelCase', [
function () {
return function (str) {
return str.replace(/-([a-z])/g, function (match) {
return match[1].toUpperCase();
});
};
}
])
/* Return the specific EditForm for a given model. */
.factory('EditForm', [
'$injector',
'CamelCase',
function ($injector, CamelCase) {
return {
fromCollectionString: function (collection) {
var modelName = CamelCase(collection).split('/')[1];
// Convert modelModel to ModelModelForm
var formName = modelName.charAt(0).toUpperCase() + modelName.slice(1) + 'Form';
return $injector.get(formName);
},
};
}
])
/* Converts number of seconds into string "h:mm:ss" or "mm:ss" */
.filter('osSecondsToTime', [
'HumanTimeConverter',

View File

@ -17,9 +17,7 @@ angular.module('OpenSlidesApp.topics.site', ['OpenSlidesApp.topics', 'OpenSlides
title: gettext('Topics'),
},
})
.state('topics.topic', {
url: '/topic',
abstract: true,
template: "<ui-view/>",
})