Merge branch 'temp8-3436-relationtypes' into temp8
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
/**
|
||||
* @ngdoc service
|
||||
* @name umbraco.resources.relationTypeResource
|
||||
* @description Loads in data for relation types.
|
||||
*/
|
||||
function relationTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
|
||||
return {
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.relationTypeResource#getById
|
||||
* @methodOf umbraco.resources.relationTypeResource
|
||||
*
|
||||
* @description
|
||||
* Gets a relation type with a given ID.
|
||||
*
|
||||
* ##usage
|
||||
* <pre>
|
||||
* relationTypeResource.getById(1234)
|
||||
* .then(function() {
|
||||
* alert('Found it!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @param {Int} id of the relation type to get.
|
||||
* @returns {Promise} resourcePromise containing relation type data.
|
||||
*/
|
||||
getById: function (id) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "GetById", [{ id: id }])),
|
||||
"Failed to get item " + id
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.relationTypeResource#getRelationObjectTypes
|
||||
* @methodof umbraco.resources.relationTypeResource
|
||||
*
|
||||
* @description
|
||||
* Gets a list of Umbraco object types which can be associated with a relation.
|
||||
*
|
||||
* @returns {Object} A collection of Umbraco object types.
|
||||
*/
|
||||
getRelationObjectTypes: function() {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get(
|
||||
umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "GetRelationObjectTypes")
|
||||
),
|
||||
"Failed to get object types"
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.relationTypeResource#save
|
||||
* @methodof umbraco.resources.relationTypeResource
|
||||
*
|
||||
* @description
|
||||
* Updates a relation type.
|
||||
*
|
||||
* @param {Object} relationType The relation type object to update.
|
||||
* @returns {Promise} A resourcePromise object.
|
||||
*/
|
||||
save: function (relationType) {
|
||||
var saveModel = umbDataFormatter.formatRelationTypePostData(relationType);
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "PostSave"), saveModel),
|
||||
"Failed to save data for relation type ID" + relationType.id
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.relationTypeResource#create
|
||||
* @methodof umbraco.resources.relationTypeResource
|
||||
*
|
||||
* @description
|
||||
* Creates a new relation type.
|
||||
*
|
||||
* @param {Object} relationType The relation type object to create.
|
||||
* @returns {Promise} A resourcePromise object.
|
||||
*/
|
||||
create: function (relationType) {
|
||||
var createModel = umbDataFormatter.formatRelationTypePostData(relationType);
|
||||
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "PostCreate"), createModel),
|
||||
"Failed to create new realtion"
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc method
|
||||
* @name umbraco.resources.relationTypeResource#deleteById
|
||||
* @methodof umbraco.resources.relationTypeResource
|
||||
*
|
||||
* @description
|
||||
* Deletes a relation type with a given ID.
|
||||
*
|
||||
* * ## Usage
|
||||
* <pre>
|
||||
* relationTypeResource.deleteById(1234).then(function() {
|
||||
* alert('Deleted it!');
|
||||
* });
|
||||
* </pre>
|
||||
*
|
||||
* @param {Int} id The ID of the relation type to delete.
|
||||
* @returns {Promose} resourcePromise object.
|
||||
*/
|
||||
deleteById: function (id) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.post(umbRequestHelper.getApiUrl("relationTypeApiBaseUrl", "DeleteById", [{ id: id }])),
|
||||
"Failed to delete item " + id
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
angular.module("umbraco.resources").factory("relationTypeResource", relationTypeResource);
|
||||
@@ -431,6 +431,24 @@
|
||||
}
|
||||
|
||||
return displayModel;
|
||||
},
|
||||
|
||||
/**
|
||||
* Formats the display model used to display the relation type to a model used to save the relation type.
|
||||
* @param {Object} relationType
|
||||
*/
|
||||
formatRelationTypePostData : function(relationType) {
|
||||
var saveModel = {
|
||||
id: relationType.id,
|
||||
name: relationType.name,
|
||||
alias: relationType.alias,
|
||||
key : relationType.key,
|
||||
isBidirectional: relationType.isBidirectional,
|
||||
parentObjectType: relationType.parentObjectType,
|
||||
childObjectType: relationType.childObjectType
|
||||
};
|
||||
|
||||
return saveModel;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @ngdoc controller
|
||||
* @name Umbraco.Editors.RelationTypes.CreateController
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* The controller for creating relation types.
|
||||
*/
|
||||
function RelationTypeCreateController($scope, $location, relationTypeResource, navigationService, formHelper, appState, notificationsService) {
|
||||
var vm = this;
|
||||
vm.relationType = {};
|
||||
vm.objectTypes = {};
|
||||
|
||||
vm.createRelationType = createRelationType;
|
||||
|
||||
init();
|
||||
|
||||
function init() {
|
||||
relationTypeResource.getRelationObjectTypes().then(function (data) {
|
||||
vm.objectTypes = data;
|
||||
}, function (err) {
|
||||
notificationsService.error("Could not load form.")
|
||||
})
|
||||
}
|
||||
|
||||
function createRelationType() {
|
||||
if (formHelper.submitForm({ scope: $scope, formCtrl: this.createRelationTypeForm, statusMessage: "Creating relation type..." })) {
|
||||
var node = $scope.currentNode;
|
||||
|
||||
relationTypeResource.create(vm.relationType).then(function (data) {
|
||||
navigationService.hideMenu();
|
||||
|
||||
// Set the new item as active in the tree
|
||||
var currentPath = node.path ? node.path : "-1";
|
||||
navigationService.syncTree({ tree: "relationTypes", path: currentPath + "," + data, forceReload: true, activate: true });
|
||||
|
||||
formHelper.resetForm({ scope: $scope });
|
||||
|
||||
var currentSection = appState.getSectionState("currentSection");
|
||||
$location.path("/" + currentSection + "/relationTypes/edit/" + data);
|
||||
}, function (err) {
|
||||
if (err.data && err.data.message) {
|
||||
notificationsService.error(err.data.message);
|
||||
navigationService.hideMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.RelationTypes.CreateController", RelationTypeCreateController);
|
||||
@@ -0,0 +1,58 @@
|
||||
<div class="umbracoDialog umb-dialog-body with-footer" ng-controller="Umbraco.Editors.RelationTypes.CreateController as vm" ng-cloak>
|
||||
<div class="umb-pane">
|
||||
<form name="createRelationTypeForm" val-form-manager ng-submit="vm.createRelationType()">
|
||||
<!-- Name -->
|
||||
<umb-control-group label="@relationType_name">
|
||||
<input type="text" name="relationTypeName" ng-model="vm.relationType.name" class="umb-textstring textstring input-block-level" umb-auto-focus required />
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Direction -->
|
||||
<umb-control-group label="@relationType_direction">
|
||||
<ul class="unstyled">
|
||||
<li>
|
||||
<label class="radio">
|
||||
<input type="radio" name="relationType-direction" ng-model="vm.relationType.isBidirectional" ng-value="false">
|
||||
<localize key="relationType_parentToChild">Parent to child</localize>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label class="radio">
|
||||
<input type="radio" name="relationType-direction" ng-model="vm.relationType.isBidirectional" ng-value="true">
|
||||
<localize key="relationType_bidirectional">Bidirectional</localize>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Parent -->
|
||||
<umb-control-group label="@relationType_parent">
|
||||
<select name="relationType-parent"
|
||||
ng-model="vm.relationType.parentObjectType"
|
||||
class="umb-property-editor umb-dropdown"
|
||||
required>
|
||||
<option ng-repeat="objectType in vm.objectTypes" value="{{objectType.id}}">{{objectType.name}}</option>
|
||||
</select>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Child -->
|
||||
<umb-control-group label="@relationType_child">
|
||||
<select name="relationType-child"
|
||||
ng-model="vm.relationType.childObjectType"
|
||||
class="umb-property-editor umb-dropdown"
|
||||
required>
|
||||
<option ng-repeat="objectType in vm.objectTypes" value="{{objectType.id}}">{{objectType.name}}</option>
|
||||
</select>
|
||||
</umb-control-group>
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<localize key="general_create">Create</localize>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="umb-dialog-footer btn-toolbar umb-btn-toolbar">
|
||||
<button class="btn btn-info">
|
||||
<localize key="buttons_somethingElse">Do something else</localize>
|
||||
</button>
|
||||
</div>
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* @ngdoc controller
|
||||
* @name Umbraco.Editors.RelationTypes.DeleteController
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* The controller for deleting relation types.
|
||||
*/
|
||||
function RelationTypeDeleteController($scope, $location, relationTypeResource, treeService, navigationService, appState) {
|
||||
|
||||
var vm = this;
|
||||
|
||||
vm.cancel = cancel;
|
||||
vm.performDelete = performDelete;
|
||||
|
||||
function cancel() {
|
||||
navigationService.hideDialog();
|
||||
}
|
||||
|
||||
function performDelete() {
|
||||
// stop from firing again on double-click
|
||||
if ($scope.busy) { return false; }
|
||||
|
||||
//mark it for deletion (used in the UI)
|
||||
$scope.currentNode.loading = true;
|
||||
$scope.busy = true;
|
||||
|
||||
relationTypeResource.deleteById($scope.currentNode.id).then(function () {
|
||||
$scope.currentNode.loading = false;
|
||||
|
||||
treeService.removeNode($scope.currentNode);
|
||||
|
||||
navigationService.hideMenu();
|
||||
|
||||
var currentSection = appState.getSectionState("currentSection");
|
||||
$location.path("/" + currentSection + "/");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.RelationTypes.DeleteController", RelationTypeDeleteController);
|
||||
@@ -0,0 +1,12 @@
|
||||
<div class="umb-dialog umb-pane" ng-controller="Umbraco.Editors.RelationTypes.DeleteController as vm">
|
||||
<div class="umb-dialog-body" auto-scale="90">
|
||||
|
||||
<p class="umb-abstract">
|
||||
<localize key="defaultdialogs_confirmdelete">Are you sure you want to delete</localize> <strong>{{currentNode.name}}</strong>?
|
||||
</p>
|
||||
|
||||
<umb-confirm on-confirm="vm.performDelete" on-cancel="vm.cancel">
|
||||
</umb-confirm>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @ngdoc controller
|
||||
* @name Umbraco.Editors.RelationTypes.EditController
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* The controller for editing relation types.
|
||||
*/
|
||||
function RelationTypeEditController($scope, $routeParams, relationTypeResource, editorState, navigationService, dateHelper, userService, entityResource, formHelper, contentEditingHelper, localizationService) {
|
||||
|
||||
var vm = this;
|
||||
|
||||
vm.page = {};
|
||||
vm.page.loading = false;
|
||||
vm.page.saveButtonState = "init";
|
||||
vm.page.menu = {}
|
||||
|
||||
vm.save = saveRelationType;
|
||||
|
||||
init();
|
||||
|
||||
function init() {
|
||||
vm.page.loading = true;
|
||||
|
||||
localizationService.localizeMany(["relationType_tabRelationType", "relationType_tabRelations"]).then(function (data) {
|
||||
vm.page.navigation = [
|
||||
{
|
||||
"name": data[0],
|
||||
"alias": "relationType",
|
||||
"icon": "icon-info",
|
||||
"view": "views/relationTypes/views/relationType.html",
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"name": data[1],
|
||||
"alias": "relations",
|
||||
"icon": "icon-trafic",
|
||||
"view": "views/relationTypes/views/relations.html"
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
relationTypeResource.getById($routeParams.id)
|
||||
.then(function(data) {
|
||||
bindRelationType(data);
|
||||
vm.page.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
function bindRelationType(relationType) {
|
||||
formatDates(relationType.relations);
|
||||
getRelationNames(relationType);
|
||||
|
||||
vm.relationType = relationType;
|
||||
|
||||
editorState.set(vm.relationType);
|
||||
|
||||
navigationService.syncTree({ tree: "relationTypes", path: relationType.path, forceReload: true }).then(function (syncArgs) {
|
||||
vm.page.menu.currentNode = syncArgs.node;
|
||||
});
|
||||
}
|
||||
|
||||
function formatDates(relations) {
|
||||
if(relations) {
|
||||
userService.getCurrentUser().then(function (currentUser) {
|
||||
angular.forEach(relations, function (relation) {
|
||||
relation.timestampFormatted = dateHelper.getLocalDate(relation.createDate, currentUser.locale, 'LLL');
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getRelationNames(relationType) {
|
||||
if(relationType.relations) {
|
||||
angular.forEach(relationType.relations, function(relation){
|
||||
entityResource.getById(relation.parentId, relationType.parentObjectTypeName).then(function(entity) {
|
||||
relation.parentName = entity.name;
|
||||
});
|
||||
entityResource.getById(relation.childId, relationType.childObjectTypeName).then(function(entity) {
|
||||
relation.childName = entity.name;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function saveRelationType() {
|
||||
vm.page.saveButtonState = "busy";
|
||||
|
||||
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
|
||||
relationTypeResource.save(vm.relationType).then(function (data) {
|
||||
formHelper.resetForm({ scope: $scope, notifications: data.notifications });
|
||||
bindRelationType(data);
|
||||
vm.page.saveButtonState = "success";
|
||||
}, function (error) {
|
||||
contentEditingHelper.handleSaveError({
|
||||
redirectOnFailure: false,
|
||||
err: error
|
||||
});
|
||||
|
||||
notificationsService.error(error.data.message);
|
||||
vm.page.saveButtonState = "error";
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
angular.module("umbraco").controller("Umbraco.Editors.RelationTypes.EditController", RelationTypeEditController);
|
||||
33
src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html
Normal file
33
src/Umbraco.Web.UI.Client/src/views/relationtypes/edit.html
Normal file
@@ -0,0 +1,33 @@
|
||||
<div data-element="editor-relation-types" ng-controller="Umbraco.Editors.RelationTypes.EditController as vm">
|
||||
<umb-load-indicator ng-if="vm.page.loading"></umb-load-indicator>
|
||||
|
||||
<form name="relationTypeForm" novalidate val-form-manager ng-submit="vm.save()">
|
||||
<umb-editor-view ng-if="!vm.page.loading">
|
||||
<umb-editor-header
|
||||
name="vm.relationType.name"
|
||||
alias="vm.relationType.alias"
|
||||
hide-description="true"
|
||||
hide-icon="true"
|
||||
navigation="vm.page.navigation">
|
||||
</umb-editor-header>
|
||||
|
||||
<umb-editor-container class="form-horizontal">
|
||||
<umb-editor-sub-views sub-views="vm.page.navigation" model="vm">
|
||||
</umb-editor-sub-views>
|
||||
</umb-editor-container>
|
||||
|
||||
<umb-editor-footer>
|
||||
<umb-editor-footer-content-right>
|
||||
<umb-button
|
||||
type="submit"
|
||||
button-style="success"
|
||||
state="vm.page.saveButtonState"
|
||||
shortcut="ctrl+s"
|
||||
label="Save"
|
||||
label-key="buttons_save">
|
||||
</umb-button>
|
||||
</umb-editor-footer-content-right>
|
||||
</umb-editor-footer>
|
||||
</umb-editor-view>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,40 @@
|
||||
<umb-box>
|
||||
<umb-box-content>
|
||||
<!-- ID -->
|
||||
<umb-control-group label="Id">
|
||||
<div>{{model.relationType.id}}</div>
|
||||
<small>{{model.relationType.key}}</small>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Direction -->
|
||||
<umb-control-group label="@relationType_direction">
|
||||
<ul class="unstyled">
|
||||
<li>
|
||||
<label class="radio">
|
||||
<input type="radio" name="relationType-direction" ng-model="model.relationType.isBidirectional" ng-value="false"> <localize key="relationType_parentToChild">Parent to child</localize>
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label class="radio">
|
||||
<input type="radio" name="relationType-direction" ng-model="model.relationType.isBidirectional" ng-value="true"> <localize key="relationType_bidirectional">Bidirectional</localize>
|
||||
</label>
|
||||
</li>
|
||||
</ul>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Parent-->
|
||||
<umb-control-group label="@relationType_parent">
|
||||
<div>{{model.relationType.parentObjectTypeName}}</div>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Child -->
|
||||
<umb-control-group label="@relationType_child">
|
||||
<div>{{model.relationType.childObjectTypeName}}</div>
|
||||
</umb-control-group>
|
||||
|
||||
<!-- Relation count -->
|
||||
<umb-control-group label="@relationType_count" ng-if="model.relationType.relations.length > 0">
|
||||
<div>{{model.relationType.relations.length}}</div>
|
||||
</umb-control-group>
|
||||
</umb-box-content>
|
||||
</umb-box>
|
||||
@@ -0,0 +1,23 @@
|
||||
<umb-box>
|
||||
<umb-box-content>
|
||||
<!-- Relations -->
|
||||
<umb-control-group label="@relationType_relations" ng-if="model.relationType.relations.length > 0">
|
||||
<div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<th><localize key="relationType_parent">Parent</localize></th>
|
||||
<th><localize key="relationType_child">Child</localize></th>
|
||||
<th><localize key="relationType_created">Created</localize></th>
|
||||
<th><localize key="relationType_comment">Comment</localize></th>
|
||||
</thead>
|
||||
<tr ng-repeat="relation in model.relationType.relations">
|
||||
<td>{{relation.parentName}}</td>
|
||||
<td>{{relation.childName}}</td>
|
||||
<td>{{relation.timestampFormatted}}</td>
|
||||
<td>{{relation.comment}}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</umb-control-group>
|
||||
</umb-box-content>
|
||||
</umb-box>
|
||||
Reference in New Issue
Block a user