From b97e2d03247c54df53679fec298a20a313b6005b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 25 Nov 2014 16:14:09 -0800 Subject: [PATCH] [Common UI] Add JSDoc, remove UUIDService Add JSDoc to Create-related classes and remove the UUIDService (replaced by third-party lib) to reduce amount of code to cover and prepare for code review, as part of ongoing transition of common user interface elements, WTD-574. --- platform/commonUI/browse/bundle.json | 6 +-- platform/commonUI/browse/lib/uuid.js | 40 +++++++++++++++++++ .../browse/src/creation/CreateWizard.js | 18 +++++++++ .../browse/src/creation/CreationService.js | 11 ++--- .../browse/src/creation/UUIDService.js | 29 -------------- 5 files changed, 65 insertions(+), 39 deletions(-) create mode 100644 platform/commonUI/browse/lib/uuid.js delete mode 100644 platform/commonUI/browse/src/creation/UUIDService.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index fedf8a8f79..36f5745de7 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -72,11 +72,7 @@ { "key": "creationService", "implementation": "creation/CreationService.js", - "depends": [ "persistenceService", "uuidService", "$q", "$log" ] - }, - { - "key": "uuidService", - "implementation": "creation/UUIDService.js" + "depends": [ "persistenceService", "$q", "$log" ] } ], "actions": [ diff --git a/platform/commonUI/browse/lib/uuid.js b/platform/commonUI/browse/lib/uuid.js new file mode 100644 index 0000000000..c51ab48544 --- /dev/null +++ b/platform/commonUI/browse/lib/uuid.js @@ -0,0 +1,40 @@ +/*global define*/ + + +/* + Adapted from: + Math.uuid.js (v1.4) + http://www.broofa.com + mailto:robert@broofa.com + + Copyright (c) 2010 Robert Kieffer + Dual licensed under the MIT and GPL licenses. +*/ +define( + function () { + 'use strict'; + return function generateUUID() { + var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'], + uuid = new Array(36), + rnd = 0, + r, + i, + offset = Math.floor(Date.now()) % 0xF; + for (i = 0; i < 36; i = i + 1) { + if (i === 8 || i === 13 || i === 18 || i === 23) { + uuid[i] = '-'; + } else if (i === 14) { + uuid[i] = '4'; + } else { + if (rnd <= 0x02) { + rnd = 0x2000000 + Math.floor(Math.random() * 0x1000000); + } + r = rnd % 0xf; + rnd = Math.floor(rnd / 16); + uuid[i] = chars[(i === 19) ? ((r % 0x3) + 0x8) : r]; + } + } + return uuid.join(''); + }; + } +); \ No newline at end of file diff --git a/platform/commonUI/browse/src/creation/CreateWizard.js b/platform/commonUI/browse/src/creation/CreateWizard.js index 15c4d8df08..475a9ff8e0 100644 --- a/platform/commonUI/browse/src/creation/CreateWizard.js +++ b/platform/commonUI/browse/src/creation/CreateWizard.js @@ -24,6 +24,14 @@ define( properties = type.getProperties(); return { + /** + * Get the form model for this wizard; this is a description + * that will be rendered to an HTML form. See the + * platform/forms bundle + * + * @return {FormModel} formModel the form model to + * show in the create dialog + */ getFormModel: function () { var parentRow = Object.create(parent), sections = []; @@ -51,9 +59,19 @@ define( name: "Create a New " + type.getName() }; }, + /** + * Based on a populated form, get the domain object which + * should be used as a parent for the newly-created object. + * @return {DomainObject} + */ getLocation: function (formValue) { return formValue.createParent || parent; }, + /** + * Create the domain object model for a newly-created object, + * based on user input read from a formModel. + * @return {object} the domain object' model + */ createModel: function (formValue) { // Clone var newModel = JSON.parse(JSON.stringify(model)); diff --git a/platform/commonUI/browse/src/creation/CreationService.js b/platform/commonUI/browse/src/creation/CreationService.js index 57ffa5f3e6..301ec7f0e8 100644 --- a/platform/commonUI/browse/src/creation/CreationService.js +++ b/platform/commonUI/browse/src/creation/CreationService.js @@ -4,8 +4,8 @@ * Module defining CreateService. Created by vwoeltje on 11/10/14. */ define( - [], - function () { + ["../../lib/uuid"], + function (uuid) { "use strict"; var NON_PERSISTENT_WARNING = @@ -14,10 +14,11 @@ define( "Could not add to composition; no composition in "; /** - * + * The creation service is responsible for instantiating and + * persisting new domain objects. This is * @constructor */ - function CreationService(persistenceService, uuidService, $q, $log) { + function CreationService(persistenceService, $q, $log) { function doPersist(space, id, model) { return persistenceService.createObject( @@ -66,7 +67,7 @@ define( if (persistence) { space = persistence.getSpace(); return $q.when( - uuidService.getUUID() + uuid() ).then(function (id) { return doPersist(space, id, model); }).then(function (id) { diff --git a/platform/commonUI/browse/src/creation/UUIDService.js b/platform/commonUI/browse/src/creation/UUIDService.js deleted file mode 100644 index 00e7fc3c3e..0000000000 --- a/platform/commonUI/browse/src/creation/UUIDService.js +++ /dev/null @@ -1,29 +0,0 @@ -/*global define,Promise*/ - -/** - * Module defining UUIDService. Created by vwoeltje on 11/12/14. - */ -define( - [], - function () { - "use strict"; - - /** - * - * @constructor - */ - function UUIDService() { - var counter = Date.now(); - - return { - getUUID: function () { - counter += 1; - return counter.toString(36); - } - - }; - } - - return UUIDService; - } -); \ No newline at end of file