From f1cf40a4c780756e032f95b472f1457767d43dbe Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Fri, 27 Mar 2015 10:01:44 +0000 Subject: [PATCH] SUPPORT : Show Broken Weak References SVN: 33754 --- .../js/views/SampleForm/SampleFormView.js | 82 +++++++++++++------ .../html/js/views/legacy/SampleLinksWidget.js | 8 +- 2 files changed, 62 insertions(+), 28 deletions(-) diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js index 10ada2d5d35..4d65110250b 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js @@ -199,6 +199,28 @@ function SampleFormView(sampleFormController, sampleFormModel) { currentParentsLinks, this._sampleFormModel.mode === FormMode.CREATE || this._sampleFormModel.mode === FormMode.EDIT); + // + // LINKS TO CHILDREN + // + var requiredChildren = []; + if(sampleTypeDefinitionsExtension && sampleTypeDefinitionsExtension["SAMPLE_CHILDREN_HINT"]) { + requiredChildren = sampleTypeDefinitionsExtension["SAMPLE_CHILDREN_HINT"]; + } + + var sampleChildrenWidgetId = "sampleChildrenWidgetId"; + var $sampleChildrenWidget = $("<div>", { "id" : sampleChildrenWidgetId }); + $formColumn.append($sampleChildrenWidget); + + var currentChildrenLinks = (this._sampleFormModel.sample)?this._sampleFormModel.sample.children:null; + this._sampleFormModel.sampleLinksChildren = new SampleLinksWidget(sampleChildrenWidgetId, + profile, + mainController.serverFacade, + "Children", + requiredChildren, + isDisabled, + currentChildrenLinks, + this._sampleFormModel.mode === FormMode.CREATE); + // // LINKS // @@ -211,7 +233,9 @@ function SampleFormView(sampleFormController, sampleFormModel) { var $sampleLinksWidget = $("<div>", { "id" : sampleLinksWidgetId }); $formColumn.append($sampleLinksWidget); - var currentOrphanLinks = []; + var currentOrphanLinksIdentifiers = []; + var currentOrphanLinksPermIds = []; + //Read the XML to build the orphan links list var annotationsFromSample = FormUtil.getAnnotationsFromSample(this._sampleFormModel.sample); //Delete parents and children @@ -230,15 +254,41 @@ function SampleFormView(sampleFormController, sampleFormModel) { //Make samples from Orphans left if(annotationsFromSample) { for(var orphanSamplePermId in annotationsFromSample) { - currentOrphanLinks.push(annotationsFromSample[orphanSamplePermId].identifier); + currentOrphanLinksIdentifiers.push(annotationsFromSample[orphanSamplePermId].identifier); + currentOrphanLinksPermIds.push(orphanSamplePermId); + } + } + + var isPresentLinkOnData = function(orphanSamplePermId, data) { + for(var dIdx = 0; dIdx <data.length; dIdx++) { + if(data[dIdx].permId === orphanSamplePermId) { + return true; + } } + return false; + } + + var buildFakeSampleIfNotFoundLink = function(orphanSamplePermId, annotationsFromSample) { + var orphanSample = {}; + orphanSample.notFound = true; + orphanSample.permId = orphanSamplePermId; + orphanSample.code = annotationsFromSample[orphanSamplePermId].identifier.split('/')[2]; + orphanSample.identifier = annotationsFromSample[orphanSamplePermId].identifier; + orphanSample.sampleTypeCode = annotationsFromSample[orphanSamplePermId].sampleType; + return orphanSample; } var showLinksWidgetAction = function(data) { + for(var oIdx = 0; oIdx < currentOrphanLinksPermIds.length; oIdx++) { + if(!isPresentLinkOnData(currentOrphanLinksPermIds[oIdx], data)) { + data.push(buildFakeSampleIfNotFoundLink(currentOrphanLinksPermIds[oIdx], annotationsFromSample)); + } + } + _this._sampleFormModel.sampleLinks = new SampleLinksWidget(sampleLinksWidgetId, profile, mainController.serverFacade, - "Links", + "Weak References", requiredLinks, isDisabled, data, @@ -246,28 +296,6 @@ function SampleFormView(sampleFormController, sampleFormModel) { _this._sampleFormModel.sampleLinks.repaint(); } - // - // LINKS TO CHILDREN - // - var requiredChildren = []; - if(sampleTypeDefinitionsExtension && sampleTypeDefinitionsExtension["SAMPLE_CHILDREN_HINT"]) { - requiredChildren = sampleTypeDefinitionsExtension["SAMPLE_CHILDREN_HINT"]; - } - - var sampleChildrenWidgetId = "sampleChildrenWidgetId"; - var $sampleChildrenWidget = $("<div>", { "id" : sampleChildrenWidgetId }); - $formColumn.append($sampleChildrenWidget); - - var currentChildrenLinks = (this._sampleFormModel.sample)?this._sampleFormModel.sample.children:null; - this._sampleFormModel.sampleLinksChildren = new SampleLinksWidget(sampleChildrenWidgetId, - profile, - mainController.serverFacade, - "Children", - requiredChildren, - isDisabled, - currentChildrenLinks, - this._sampleFormModel.mode === FormMode.CREATE); - // // GENERATE CHILDREN // @@ -443,8 +471,8 @@ function SampleFormView(sampleFormController, sampleFormModel) { this._sampleFormModel.sampleLinksParents.repaint(); this._sampleFormModel.sampleLinksChildren.repaint(); - if(currentOrphanLinks.length !== 0) { - mainController.serverFacade.searchWithIdentifiers(currentOrphanLinks, showLinksWidgetAction); + if(currentOrphanLinksIdentifiers.length !== 0) { + mainController.serverFacade.searchWithIdentifiers(currentOrphanLinksIdentifiers, showLinksWidgetAction); } else { showLinksWidgetAction([]); } diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleLinksWidget.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleLinksWidget.js index 22bb33521df..c25e2421fa4 100644 --- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleLinksWidget.js +++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/legacy/SampleLinksWidget.js @@ -495,7 +495,13 @@ function SampleLinksWidget(containerId, profile, serverFacade, title, sampleType var codeLink = sampleToAdd.code; if(this.isDisabled) { - codeLink = $("<a>").append(sampleToAdd.code); + var style = ""; + var notFound = ""; + if(sampleToAdd.notFound) { + style = "color: red;" + notFound = " (Not Found)" + } + codeLink = $("<a>", { "style" : style }).append(sampleToAdd.code + notFound); codeLink.click(function() { var url = document.location.href; -- GitLab