public/app/admin/create.js
// This is our controller...  think of it as a controller with a view model in it
This is our controller...  think of it as a controller with a view model in it
This is our controller ... think of it as a controller with a view model in it
function createCtrl(common, datacontext, $window) {
        var getLogFn = common.logger.getLogFn;
        var log = getLogFn(controllerId);
        var logError = getLogFn(controllerId, 'error');
        var today = new Date();
        var vm = this;
        vm.primerDesignerReturn = [];
        vm.runPrimerDesigner = runPrimerDesigner;
        vm.addManualPrimer = addManualPrimer;
        activate();
        function activate() {
            var promises = [];
            common.activateController(promises, controllerId)
                .then(function (){});
        }
        function runPrimerDesigner(){
            var inputCheck = common.checkGenomicTargetForm(vm.newAutoRegionOfInterest);
            if (inputCheck.error){
                logError(inputCheck.errorMessage);
                return;
            }
            return datacontext.runPrimerDesigner(vm.newAutoRegionOfInterest).then(function (result) {
                vm.primerDesignerReturn = jQuery.parseJSON(result.data.stdout);
                if (vm.primerDesignerReturn.leftSequence == null || vm.primerDesignerReturn.leftTm == null || vm.primerDesignerReturn.rightSequence == null || vm.primerDesignerReturn.rightTm == null || vm.primerDesignerReturn.chromosome == null || vm.primerDesignerReturn.startPosition == null || vm.primerDesignerReturn.endPosition == null){
                    logError("Could not designer primers around the supplied target");
                    return;
                }
                var query = "CREATE (primer1:Primer {PrimerSequence:\"" + vm.primerDesignerReturn.leftSequence + "\", Tm:" + vm.primerDesignerReturn.leftTm + "}), ";
                query += "(primer2:Primer {PrimerSequence:\"" + vm.primerDesignerReturn.rightSequence + "\", Tm:" + vm.primerDesignerReturn.rightTm + "}), ";
                query += "(primer1)-[:HAS_DOWNSTREAM_TARGET]->(assay:Assay {Contig:\"" + vm.primerDesignerReturn.chromosome + "\", StartPos:toInt(" + vm.primerDesignerReturn.startPosition + "), EndPos:toInt(" + vm.primerDesignerReturn.endPosition + "), ReferenceGenome:\"GRCh37\"})<-[:HAS_UPSTREAM_TARGET]-(primer2);";
                return datacontext.runAdhocQuery(query).then(function (result) {
                    var cypherReturn  = common.checkCypherLog(result.data);
                    if (cypherReturn.error){
                        logError(cypherReturn.errorMessage);
                    } else {
                        log("Operation Successful");
                        if (cypherReturn.successMessage != "" && cypherReturn.successMessage != undefined) log(cypherReturn.successMessage);
                    }
                });
            });
        }
        function addManualPrimer() {
            var upstreamProvided = false, downstreamProvided = false;
            var query = "MATCH (user:User {UserName:\"" + $window.sessionStorage.username + "\"}) ";
            if (vm.newManualUpstreamPrimerSequence != undefined && vm.newManualUpstreamPrimerSequence != ""){
                upstreamProvided = true;
                var checkInput = common.checkDNAIsIUPAC(vm.newManualUpstreamPrimerSequence);
                if (checkInput.error){
                    logError("Upstream primer error: " + checkInput.errorMessage);
                    return;
                }
                if (vm.newManualUpstreamPrimerTm == undefined || vm.newManualUpstreamPrimerTm == ""){
                    logError('Enter upstream primer Tm');
                    return;
                }
            }
            if (vm.newManualDownstreamPrimerSequence != undefined && vm.newManualDownstreamPrimerSequence != ""){
                downstreamProvided = true;
                var checkInput = common.checkDNAIsIUPAC(vm.newManualDownstreamPrimerSequence);
                if (checkInput.error){
                    logError("Downstream primer error: " + checkInput.errorMessage);
                    return;
                }
                if (vm.newManualDownstreamPrimerTm == undefined || vm.newManualDownstreamPrimerTm == ""){
                    logError('Enter downstream primer Tm');
                    return;
                }
            }
            if (upstreamProvided && downstreamProvided){
                if (vm.newManualTargetRegion == undefined || vm.newManualTargetRegion == ""){
                    logError('Enter a target region');
                    return;
                } else {
                    var checkInput = common.checkGenomicTargetForm(vm.newManualTargetRegion);
                    if (checkInput.error){
                        logError(checkInput.errorMessage);
                        return;
                    }
                }
                var fields = vm.newManualTargetRegion.split(/:|-/);
                query += "CREATE (primer1:Primer {PrimerSequence:\"" + vm.newManualUpstreamPrimerSequence.toUpperCase() + "\", Tm: " + vm.newManualUpstreamPrimerTm;
                if (vm.newManualUpstreamPrimerComments != undefined && vm.newManualUpstreamPrimerComments != "") query += ", Comments:\"" + vm.newManualUpstreamPrimerComments + "\"";
                query += "})-[:ENTERED_BY {Date:" + today.getTime() + "}]->(user), ";
                query += "(primer2:Primer {PrimerSequence:\"" + vm.newManualDownstreamPrimerSequence.toUpperCase() + "\", Tm: " + vm.newManualDownstreamPrimerTm;
                if (vm.newManualDownstreamPrimerComments != undefined && vm.newManualDownstreamPrimerComments != "") query += ", Comments:\"" + vm.newManualDownstreamPrimerComments + "\"";
                query += "})-[:ENTERED_BY {Date:" + today.getTime() + "}]->(user), ";
                query += "(primer1)-[:HAS_DOWNSTREAM_TARGET]->(assay:Assay {Contig:\"" + fields[0] + "\", StartPos:toInt(" + fields[1] + "), EndPos:toInt(" + fields[2] + "), ReferenceGenome:\"GRCh37\"})<-[:HAS_UPSTREAM_TARGET]-(primer2), ";
                query += "(assay)-[:DESIGNED_BY {Date:" + today.getTime() + "}]->(user);"
            } else if (upstreamProvided) {
                query += "CREATE (primer:Primer {PrimerSequence:\"" + vm.newManualUpstreamPrimerSequence.toUpperCase() + "\", Tm: " + vm.newManualUpstreamPrimerTm;
                if (vm.newManualUpstreamPrimerComments != undefined && vm.newManualUpstreamPrimerComments != "") query += ", Comments:\"" + vm.newManualUpstreamPrimerComments + "\"";
                query += "})-[:ENTERED_BY {Date:" + today.getTime() + "}]->(user);";
            } else if (downstreamProvided){
                query += "CREATE (primer:Primer {PrimerSequence:\"" + vm.newManualDownstreamPrimerSequence.toUpperCase() + "\", Tm: " + vm.newManualDownstreamPrimerTm;
                if (vm.newManualDownstreamPrimerComments != undefined && vm.newManualDownstreamPrimerComments != "") query += ", Comments:\"" + vm.newManualDownstreamPrimerComments + "\"";
                query += "})-[:ENTERED_BY {Date:" + today.getTime() + "}]->(user);";
            }
            return datacontext.runAdhocQuery(query).then(function (result) {
                var cypherReturn  = common.checkCypherLog(result.data);
                if (cypherReturn.error){
                    logError(cypherReturn.errorMessage);
                } else {
                    log("Operation Successful");
                    if (cypherReturn.successMessage != "" && cypherReturn.successMessage != undefined) log(cypherReturn.successMessage);
                }
            });
        }
    }
function createCtrl ( common , datacontext , $window ) { var getLogFn = common . logger . getLogFn ; var log = getLogFn ( controllerId ) ; var logError = getLogFn ( controllerId , 'error' ) ; var today = new Date ( ) ; var vm = this ; vm . primerDesignerReturn = [ ] ; vm . runPrimerDesigner = runPrimerDesigner ; vm . addManualPrimer = addManualPrimer ; activate ( ) ; function activate ( ) { var promises = [ ] ; common . activateController ( promises , controllerId ) . then ( function ( ) { } ) ; } function runPrimerDesigner ( ) { var inputCheck = common . checkGenomicTargetForm ( vm . newAutoRegionOfInterest ) ; if ( inputCheck . error ) { logError ( inputCheck . errorMessage ) ; return ; } return datacontext . runPrimerDesigner ( vm . newAutoRegionOfInterest ) . then ( function ( result ) { vm . primerDesignerReturn = jQuery . parseJSON ( result . data . stdout ) ; if ( vm . primerDesignerReturn . leftSequence == null || vm . primerDesignerReturn . leftTm == null || vm . primerDesignerReturn . rightSequence == null || vm . primerDesignerReturn . rightTm == null || vm . primerDesignerReturn . chromosome == null || vm . primerDesignerReturn . startPosition == null || vm . primerDesignerReturn . endPosition == null ) { logError ( "Could not designer primers around the supplied target" ) ; return ; } var query = "CREATE (primer1:Primer {PrimerSequence:\"" + vm . primerDesignerReturn . leftSequence + "\", Tm:" + vm . primerDesignerReturn . leftTm + "}), " ; query += "(primer2:Primer {PrimerSequence:\"" + vm . primerDesignerReturn . rightSequence + "\", Tm:" + vm . primerDesignerReturn . rightTm + "}), " ; query += "(primer1)-[:HAS_DOWNSTREAM_TARGET]->(assay:Assay {Contig:\"" + vm . primerDesignerReturn . chromosome + "\", StartPos:toInt(" + vm . primerDesignerReturn . startPosition + "), EndPos:toInt(" + vm . primerDesignerReturn . endPosition + "), ReferenceGenome:\"GRCh37\"})<-[:HAS_UPSTREAM_TARGET]-(primer2);" ; return datacontext . runAdhocQuery ( query ) . then ( function ( result ) { var cypherReturn = common . checkCypherLog ( result . data ) ; if ( cypherReturn . error ) { logError ( cypherReturn . errorMessage ) ; } else { log ( "Operation Successful" ) ; if ( cypherReturn . successMessage != "" && cypherReturn . successMessage != undefined ) log ( cypherReturn . successMessage ) ; } } ) ; } ) ; } function addManualPrimer ( ) { var upstreamProvided = false , downstreamProvided = false ; var query = "MATCH (user:User {UserName:\"" + $window . sessionStorage . username + "\"}) " ; if ( vm . newManualUpstreamPrimerSequence != undefined && vm . newManualUpstreamPrimerSequence != "" ) { upstreamProvided = true ; var checkInput = common . checkDNAIsIUPAC ( vm . newManualUpstreamPrimerSequence ) ; if ( checkInput . error ) { logError ( "Upstream primer error: " + checkInput . errorMessage ) ; return ; } if ( vm . newManualUpstreamPrimerTm == undefined || vm . newManualUpstreamPrimerTm == "" ) { logError ( 'Enter upstream primer Tm' ) ; return ; } } if ( vm . newManualDownstreamPrimerSequence != undefined && vm . newManualDownstreamPrimerSequence != "" ) { downstreamProvided = true ; var checkInput = common . checkDNAIsIUPAC ( vm . newManualDownstreamPrimerSequence ) ; if ( checkInput . error ) { logError ( "Downstream primer error: " + checkInput . errorMessage ) ; return ; } if ( vm . newManualDownstreamPrimerTm == undefined || vm . newManualDownstreamPrimerTm == "" ) { logError ( 'Enter downstream primer Tm' ) ; return ; } } if ( upstreamProvided && downstreamProvided ) { if ( vm . newManualTargetRegion == undefined || vm . newManualTargetRegion == "" ) { logError ( 'Enter a target region' ) ; return ; } else { var checkInput = common . checkGenomicTargetForm ( vm . newManualTargetRegion ) ; if ( checkInput . error ) { logError ( checkInput . errorMessage ) ; return ; } } var fields = vm . newManualTargetRegion . split ( / :|- / ) ; query += "CREATE (primer1:Primer {PrimerSequence:\"" + vm . newManualUpstreamPrimerSequence . toUpperCase ( ) + "\", Tm: " + vm . newManualUpstreamPrimerTm ; if ( vm . newManualUpstreamPrimerComments != undefined && vm . newManualUpstreamPrimerComments != "" ) query += ", Comments:\"" + vm . newManualUpstreamPrimerComments + "\"" ; query += "})-[:ENTERED_BY {Date:" + today . getTime ( ) + "}]->(user), " ; query += "(primer2:Primer {PrimerSequence:\"" + vm . newManualDownstreamPrimerSequence . toUpperCase ( ) + "\", Tm: " + vm . newManualDownstreamPrimerTm ; if ( vm . newManualDownstreamPrimerComments != undefined && vm . newManualDownstreamPrimerComments != "" ) query += ", Comments:\"" + vm . newManualDownstreamPrimerComments + "\"" ; query += "})-[:ENTERED_BY {Date:" + today . getTime ( ) + "}]->(user), " ; query += "(primer1)-[:HAS_DOWNSTREAM_TARGET]->(assay:Assay {Contig:\"" + fields [ 0 ] + "\", StartPos:toInt(" + fields [ 1 ] + "), EndPos:toInt(" + fields [ 2 ] + "), ReferenceGenome:\"GRCh37\"})<-[:HAS_UPSTREAM_TARGET]-(primer2), " ; query += "(assay)-[:DESIGNED_BY {Date:" + today . getTime ( ) + "}]->(user);" } else if ( upstreamProvided ) { query += "CREATE (primer:Primer {PrimerSequence:\"" + vm . newManualUpstreamPrimerSequence . toUpperCase ( ) + "\", Tm: " + vm . newManualUpstreamPrimerTm ; if ( vm . newManualUpstreamPrimerComments != undefined && vm . newManualUpstreamPrimerComments != "" ) query += ", Comments:\"" + vm . newManualUpstreamPrimerComments + "\"" ; query += "})-[:ENTERED_BY {Date:" + today . getTime ( ) + "}]->(user);" ; } else if ( downstreamProvided ) { query += "CREATE (primer:Primer {PrimerSequence:\"" + vm . newManualDownstreamPrimerSequence . toUpperCase ( ) + "\", Tm: " + vm . newManualDownstreamPrimerTm ; if ( vm . newManualDownstreamPrimerComments != undefined && vm . newManualDownstreamPrimerComments != "" ) query += ", Comments:\"" + vm . newManualDownstreamPrimerComments + "\"" ; query += "})-[:ENTERED_BY {Date:" + today . getTime ( ) + "}]->(user);" ; } return datacontext . runAdhocQuery ( query ) . then ( function ( result ) { var cypherReturn = common . checkCypherLog ( result . data ) ; if ( cypherReturn . error ) { logError ( cypherReturn . errorMessage ) ; } else { log ( "Operation Successful" ) ; if ( cypherReturn . successMessage != "" && cypherReturn . successMessage != undefined ) log ( cypherReturn . successMessage ) ; } } ) ; } }
This is our controller...  think of it as a controller with a view model in it
This is our controller ... think of it as a controller with a view model in it
// Organizing all of the variables and functions here allows us to get a quick look at // what the controller is doing // Our event handlers // Call this function when our controller is loaded ///auto new designer primer //check input is correct //activate spinner //TODO activate spinner //deactivate spinner //TODO deactivate spinner //add upstream primer and order //add manual primer //check upstream primer entry //check Tm has been entered //check downstream primer entry //check Tm has been entered //check and extract target region //add primer(s) //if (vm.newManualSNPDBExcluded != undefined && vm.newManualSNPDBExcluded != "") query += ", SNPDB:\"" + vm.newManualSNPDBExcluded + "\""; //if (vm.newManualSNPDBExcluded != undefined && vm.newManualSNPDBExcluded != "") query += ", SNPDB:\"" + vm.newManualSNPDBExcluded + "\""; //if (vm.newManualSNPDBExcluded != undefined && vm.newManualSNPDBExcluded != "") query += ", SNPDB:\"" + vm.newManualSNPDBExcluded + "\""; //if (vm.newManualSNPDBExcluded != undefined && vm.newManualSNPDBExcluded != "") query += ", SNPDB:\"" + vm.newManualSNPDBExcluded + "\"";