2015-03-03 16:18:24 +00:00
"use strict" ;
2014-11-11 16:23:58 +00:00
/ * A l l s h a r e d f u n c t i o n a l i t y t o g o i n l i b t o a s t e r o b j e c t .
* This object really just helps readability since we can then have
* a traceable namespace .
* /
2016-04-12 11:07:01 +00:00
var libtoaster = ( function ( ) {
// prevent conflicts with Bootstrap 2's typeahead (required during
// transition from v2 to v3)
var typeahead = jQuery . fn . typeahead . noConflict ( ) ;
jQuery . fn . _typeahead = typeahead ;
/ * M a k e a t y p e a h e a d f r o m a n i n p u t e l e m e n t
*
* _makeTypeahead parameters
* jQElement : input element as selected by $ ( 'selector' )
* xhrUrl : the url to get the JSON from ; this URL should return JSON in the
* format :
* { "results" : [ { "name" : "test" , "detail" : "a test thing" } , ... ] }
2014-11-11 16:23:58 +00:00
* xhrParams : the data / parameters to pass to the getJSON url e . g .
2016-04-12 11:07:01 +00:00
* { 'type' : 'projects' } ; the text typed will be passed as 'search' .
* selectedCB : function to call once an item has been selected ; has
* signature selectedCB ( item ) , where item is an item in the format shown
* in the JSON list above , i . e .
* { "name" : "name" , "detail" : "detail" } .
2014-11-11 16:23:58 +00:00
* /
2016-04-12 11:07:01 +00:00
function _makeTypeahead ( jQElement , xhrUrl , xhrParams , selectedCB ) {
if ( ! xhrUrl || xhrUrl . length === 0 ) {
throw ( "No url supplied for typeahead" ) ;
}
2014-11-11 16:23:58 +00:00
2015-08-04 19:46:39 +00:00
var xhrReq ;
2016-04-12 11:07:01 +00:00
jQElement . _typeahead (
{
highlight : true ,
classNames : {
open : "dropdown-menu" ,
cursor : "active"
}
} ,
{
source : function ( query , syncResults , asyncResults ) {
2015-05-19 15:14:29 +00:00
xhrParams . search = query ;
2015-08-04 19:46:39 +00:00
2016-04-12 11:07:01 +00:00
// if we have a request in progress, cancel it and start another
if ( xhrReq ) {
2015-08-04 19:46:39 +00:00
xhrReq . abort ( ) ;
2016-04-12 11:07:01 +00:00
}
2015-08-04 19:46:39 +00:00
2016-04-12 11:07:01 +00:00
xhrReq = $ . getJSON ( xhrUrl , xhrParams , function ( data ) {
2015-03-03 16:18:24 +00:00
if ( data . error !== "ok" ) {
2016-04-12 11:07:01 +00:00
console . error ( "Error getting data from server: " + data . error ) ;
2014-11-26 15:05:07 +00:00
return ;
}
2015-08-04 19:46:39 +00:00
xhrReq = null ;
2016-04-12 11:07:01 +00:00
asyncResults ( data . results ) ;
2014-11-11 16:23:58 +00:00
} ) ;
} ,
2015-08-04 19:46:39 +00:00
2016-04-12 11:07:01 +00:00
// how the selected item is shown in the input
display : function ( item ) {
return item . name ;
2015-07-31 12:09:15 +00:00
} ,
2015-08-04 19:46:40 +00:00
2016-04-12 11:07:01 +00:00
templates : {
// how the item is displayed in the dropdown
suggestion : function ( item ) {
var elt = document . createElement ( "div" ) ;
elt . innerHTML = item . name + " " + item . detail ;
return elt ;
}
}
}
) ;
2014-11-11 16:23:58 +00:00
2016-04-12 11:07:01 +00:00
// when an item is selected using the typeahead, invoke the callback
jQElement . on ( "typeahead:select" , function ( event , item ) {
selectedCB ( item ) ;
} ) ;
2015-03-03 16:18:24 +00:00
}
2014-11-11 16:23:58 +00:00
2016-04-06 16:46:32 +00:00
/ * s t a r t A B u i l d :
* url : xhr _buildrequest or null for current project
* targets : an array or space separated list of targets to build
* onsuccess : callback for successful execution
* onfail : callback for failed execution
* /
function _startABuild ( url , targets , onsuccess , onfail ) {
2014-11-11 16:23:58 +00:00
2016-04-06 16:46:32 +00:00
if ( ! url )
url = libtoaster . ctx . xhrBuildRequestUrl ;
/* Flatten the array of targets into a space spearated list */
if ( targets instanceof Array ) {
targets = targets . reduce ( function ( prevV , nextV ) {
return prev + ' ' + next ;
} ) ;
2015-03-27 15:49:55 +00:00
}
2014-11-11 16:23:58 +00:00
$ . ajax ( {
type : "POST" ,
url : url ,
2016-04-06 16:46:32 +00:00
data : { 'targets' : targets } ,
2014-11-11 16:23:58 +00:00
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( _data ) {
2015-03-03 16:18:24 +00:00
if ( _data . error !== "ok" ) {
2015-01-08 13:15:10 +00:00
console . warn ( _data . error ) ;
2016-04-06 16:46:32 +00:00
} else {
2015-03-03 16:18:24 +00:00
if ( onsuccess !== undefined ) onsuccess ( _data ) ;
2016-04-06 16:46:32 +00:00
}
2014-11-11 16:23:58 +00:00
} ,
error : function ( _data ) {
2015-01-08 13:15:10 +00:00
console . warn ( "Call failed" ) ;
console . warn ( _data ) ;
2014-11-11 16:23:58 +00:00
if ( onfail ) onfail ( data ) ;
} } ) ;
2015-03-03 16:18:24 +00:00
}
2014-11-11 16:23:58 +00:00
2015-03-13 14:34:41 +00:00
/ * c a n c e l A B u i l d :
2016-04-06 16:46:32 +00:00
* url : xhr _buildrequest url or null for current project
* buildRequestIds : space separated list of build request ids
2015-03-13 14:34:41 +00:00
* onsuccess : callback for successful execution
* onfail : callback for failed execution
* /
2016-04-06 16:46:32 +00:00
function _cancelABuild ( url , buildRequestIds , onsuccess , onfail ) {
if ( ! url )
url = libtoaster . ctx . xhrBuildRequestUrl ;
2015-03-13 14:34:41 +00:00
$ . ajax ( {
type : "POST" ,
url : url ,
2016-04-06 16:46:32 +00:00
data : { 'buildCancel' : buildRequestIds } ,
2015-03-13 14:34:41 +00:00
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( _data ) {
if ( _data . error !== "ok" ) {
console . warn ( _data . error ) ;
} else {
2016-04-06 16:46:32 +00:00
if ( onsuccess ) onsuccess ( _data ) ;
2015-03-13 14:34:41 +00:00
}
} ,
error : function ( _data ) {
console . warn ( "Call failed" ) ;
console . warn ( _data ) ;
2015-04-21 10:59:37 +00:00
if ( onfail ) onfail ( _data ) ;
2015-03-13 14:34:41 +00:00
}
} ) ;
}
bitbake: toaster: move most recent builds templating to client
The most recent builds area of the all builds and project builds
table needs to update as a build progresses. It also needs
additional functionality to show other states (e.g. recipe parsing,
queued) which again needs to update on the client side.
Rather than add to the existing mix of server-side templating
with client-side DOM updating, translate all of the server-side
templates to client-side ones (jsrender), and add logic which
updates the most recent builds area as the state of a build changes.
Add a JSON API for mostrecentbuilds, which returns the state of
all "recent" builds. Fetch this via Ajax from the build dashboard
(rather than fetching the ad hoc API as in the previous version).
Then, as new states for builds are fetched via Ajax, determine
whether the build state has changed completely, or whether the progress
has just updated. If the state completely changed, re-render the
template on the client side for that build. If only the progress
changed, just update the progress bar. (NB this fixes the
task progress bar so it works for the project builds and all builds
pages.)
In cases where the builds table needs to update as the result of
a build finishing, reload the whole page.
This work highlighted a variety of other issues, such as
build requests not being able to change state as necessary. This
was one part of the cause of the "cancelling build..." state
being fragile and disappearing entirely when the page refreshed.
The cancelling state now persists between page reloads, as the
logic for determining whether a build is cancelling is now on
the Build object itself.
Note that jsrender is redistributed as part of Toaster, so
a note was added to LICENSE to that effect.
[YOCTO #9631]
(Bitbake rev: c868ea036aa34b387a72ec5116a66b2cd863995b)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-06-29 14:41:56 +00:00
function _getMostRecentBuilds ( url , onsuccess , onfail ) {
$ . ajax ( {
url : url ,
type : 'GET' ,
data : { format : 'json' } ,
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( data ) {
onsuccess ? onsuccess ( data ) : console . log ( data ) ;
} ,
error : function ( data ) {
onfail ? onfail ( data ) : console . error ( data ) ;
}
} ) ;
}
2014-11-14 18:12:20 +00:00
/* Get a project's configuration info */
2015-06-08 17:41:46 +00:00
function _getProjectInfo ( url , onsuccess , onfail ) {
2014-11-14 18:12:20 +00:00
$ . ajax ( {
2015-06-08 17:41:46 +00:00
type : "GET" ,
2014-11-14 18:12:20 +00:00
url : url ,
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( _data ) {
2015-03-03 16:18:24 +00:00
if ( _data . error !== "ok" ) {
2015-01-08 13:15:10 +00:00
console . warn ( _data . error ) ;
2014-11-14 18:12:20 +00:00
} else {
2015-03-03 16:18:24 +00:00
if ( onsuccess !== undefined ) onsuccess ( _data ) ;
2014-11-14 18:12:20 +00:00
}
} ,
error : function ( _data ) {
2015-01-08 13:15:10 +00:00
console . warn ( _data ) ;
2015-03-03 16:18:24 +00:00
if ( onfail ) onfail ( _data ) ;
2014-11-14 18:12:20 +00:00
}
} ) ;
2015-03-03 16:18:24 +00:00
}
2014-11-14 18:12:20 +00:00
2014-11-26 15:06:47 +00:00
/ * P r o p e r t i e s f o r d a t a c a n b e :
* layerDel ( csv )
* layerAdd ( csv )
* projectName
* projectVersion
* machineName
* /
2015-04-10 17:15:03 +00:00
function _editCurrentProject ( data , onSuccess , onFail ) {
2014-11-26 15:06:47 +00:00
$ . ajax ( {
type : "POST" ,
2016-09-26 10:59:28 +00:00
url : libtoaster . ctx . xhrProjectUrl ,
2014-11-26 15:06:47 +00:00
data : data ,
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( data ) {
if ( data . error != "ok" ) {
console . log ( data . error ) ;
2015-03-03 16:18:24 +00:00
if ( onFail !== undefined )
2014-11-26 15:06:47 +00:00
onFail ( data ) ;
} else {
2015-03-03 16:18:24 +00:00
if ( onSuccess !== undefined )
2014-11-26 15:06:47 +00:00
onSuccess ( data ) ;
}
} ,
error : function ( data ) {
console . log ( "Call failed" ) ;
console . log ( data ) ;
}
} ) ;
2015-03-03 16:18:24 +00:00
}
2014-11-26 15:06:47 +00:00
2015-06-08 14:22:01 +00:00
function _getLayerDepsForProject ( url , onSuccess , onFail ) {
2014-11-26 15:06:47 +00:00
/* Check for dependencies not in the current project */
2015-06-08 14:22:01 +00:00
$ . getJSON ( url ,
{ format : 'json' } ,
2014-11-26 15:06:47 +00:00
function ( data ) {
if ( data . error != "ok" ) {
console . log ( data . error ) ;
2015-03-03 16:18:24 +00:00
if ( onFail !== undefined )
2014-11-26 15:06:47 +00:00
onFail ( data ) ;
} else {
2015-07-31 12:09:12 +00:00
var deps = { } ;
/ * F i l t e r o u t l a y e r d e p i d s w h i c h a r e i n t h e
* project already .
* /
deps . list = data . layerdeps . list . filter ( function ( layerObj ) {
return ( data . projectlayers . lastIndexOf ( layerObj . id ) < 0 ) ;
} ) ;
onSuccess ( deps ) ;
2014-11-26 15:06:47 +00:00
}
} , function ( ) {
console . log ( "E: Failed to make request" ) ;
} ) ;
2015-03-03 16:18:24 +00:00
}
2014-11-26 15:06:47 +00:00
2015-01-14 12:46:52 +00:00
/* parses the query string of the current window.location to an object */
function _parseUrlParams ( ) {
2015-03-03 16:18:24 +00:00
var string = window . location . search ;
2015-01-14 12:46:52 +00:00
string = string . substr ( 1 ) ;
2015-03-03 16:18:24 +00:00
var stringArray = string . split ( "&" ) ;
var obj = { } ;
2015-01-14 12:46:52 +00:00
2015-03-03 16:18:24 +00:00
for ( var i in stringArray ) {
var keyVal = stringArray [ i ] . split ( "=" ) ;
2015-01-14 12:46:52 +00:00
obj [ keyVal [ 0 ] ] = keyVal [ 1 ] ;
}
return obj ;
2015-03-03 16:18:24 +00:00
}
2015-01-14 12:46:52 +00:00
/ * t a k e s a f l a t o b j e c t a n d o u t p u t s i t a s a q u e r y s t r i n g
* e . g . the output of dumpsUrlParams
* /
function _dumpsUrlParams ( obj ) {
var str = "?" ;
2015-03-03 16:18:24 +00:00
for ( var key in obj ) {
2015-01-14 12:46:52 +00:00
if ( ! obj [ key ] )
continue ;
str += key + "=" + obj [ key ] . toString ( ) ;
str += "&" ;
}
2015-05-18 19:08:28 +00:00
/* Maintain the current hash */
str += window . location . hash ;
2015-01-14 12:46:52 +00:00
return str ;
2015-03-03 16:18:24 +00:00
}
2015-01-14 12:46:52 +00:00
2015-04-21 10:59:37 +00:00
function _addRmLayer ( layerObj , add , doneCb ) {
2016-12-09 16:52:53 +00:00
if ( layerObj . xhrLayerUrl === undefined ) {
throw ( "xhrLayerUrl is undefined" )
}
2015-04-21 10:59:37 +00:00
if ( add === true ) {
/* If adding get the deps for this layer */
2016-12-09 16:52:53 +00:00
libtoaster . getLayerDepsForProject ( layerObj . xhrLayerUrl ,
2015-04-21 10:59:37 +00:00
function ( layers ) {
/* got result for dependencies */
if ( layers . list . length === 0 ) {
var editData = { layerAdd : layerObj . id } ;
libtoaster . editCurrentProject ( editData , function ( ) {
doneCb ( [ ] ) ;
} ) ;
return ;
} else {
try {
showLayerDepsModal ( layerObj , layers . list , null , null , true , doneCb ) ;
} catch ( e ) {
$ . getScript ( libtoaster . ctx . jsUrl + "layerDepsModal.js" , function ( ) {
showLayerDepsModal ( layerObj , layers . list , null , null , true , doneCb ) ;
} , function ( ) {
console . warn ( "Failed to load layerDepsModal" ) ;
} ) ;
}
}
} , null ) ;
} else if ( add === false ) {
var editData = { layerDel : layerObj . id } ;
libtoaster . editCurrentProject ( editData , function ( ) {
doneCb ( [ ] ) ;
} , function ( ) {
console . warn ( "Removing layer from project failed" ) ;
doneCb ( null ) ;
} ) ;
}
}
function _makeLayerAddRmAlertMsg ( layer , layerDepsList , add ) {
var alertMsg ;
if ( layerDepsList . length > 0 && add === true ) {
2016-04-12 14:56:43 +00:00
alertMsg = $ ( "<span>You have added <strong>" + ( layerDepsList . length + 1 ) + "</strong> layers to your project: <a class=\"alert-link\" id=\"layer-affected-name\"></a> and its dependencies </span>" ) ;
2015-04-21 10:59:37 +00:00
/* Build the layer deps list */
layerDepsList . map ( function ( layer , i ) {
2016-04-12 14:56:43 +00:00
var link = $ ( "<a class=\"alert-link\"></a>" ) ;
2015-04-21 10:59:37 +00:00
link . attr ( "href" , layer . layerdetailurl ) ;
link . text ( layer . name ) ;
link . tooltip ( { title : layer . tooltip } ) ;
if ( i !== 0 )
alertMsg . append ( ", " ) ;
alertMsg . append ( link ) ;
} ) ;
} else if ( layerDepsList . length === 0 && add === true ) {
2016-04-12 14:56:43 +00:00
alertMsg = $ ( "<span>You have added <strong>1</strong> layer to your project: <a class=\"alert-link\" id=\"layer-affected-name\"></a></span></span>" ) ;
2015-04-21 10:59:37 +00:00
} else if ( add === false ) {
2016-04-12 14:56:43 +00:00
alertMsg = $ ( "<span>You have removed <strong>1</strong> layer from your project: <a class=\"alert-link\" id=\"layer-affected-name\"></a></span>" ) ;
2015-04-21 10:59:37 +00:00
}
alertMsg . children ( "#layer-affected-name" ) . text ( layer . name ) ;
2015-07-31 12:09:07 +00:00
alertMsg . children ( "#layer-affected-name" ) . attr ( "href" , layer . layerdetailurl ) ;
2015-04-21 10:59:37 +00:00
return alertMsg . html ( ) ;
}
2015-07-31 12:09:08 +00:00
function _showChangeNotification ( message ) {
2016-10-06 00:08:53 +00:00
$ ( ".alert-dismissible" ) . fadeOut ( ) . promise ( ) . done ( function ( ) {
2016-09-26 10:59:32 +00:00
var alertMsg = $ ( "#change-notification-msg" ) ;
2015-07-31 12:09:08 +00:00
2016-09-26 10:59:32 +00:00
alertMsg . html ( message ) ;
$ ( "#change-notification, #change-notification *" ) . fadeIn ( ) ;
} ) ;
2015-07-31 12:09:08 +00:00
}
2015-12-07 18:43:15 +00:00
function _createCustomRecipe ( name , baseRecipeId , doneCb ) {
var data = {
'name' : name ,
'project' : libtoaster . ctx . projectId ,
'base' : baseRecipeId ,
} ;
$ . ajax ( {
type : "POST" ,
url : libtoaster . ctx . xhrCustomRecipeUrl ,
data : data ,
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( ret ) {
if ( doneCb ) {
doneCb ( ret ) ;
} else if ( ret . error !== "ok" ) {
console . warn ( ret . error ) ;
}
} ,
error : function ( ret ) {
console . warn ( "Call failed" ) ;
console . warn ( ret ) ;
}
} ) ;
}
2016-05-09 23:01:48 +00:00
/ * V a l i d a t e p r o j e c t n a m e s . U s e u n i q u e p r o j e c t n a m e s
All arguments accepted by this function are JQeury objects .
For example if the HTML element has "hint-error-project-name" , then
it is passed to this function as $ ( "#hint-error-project-name" ) .
Arg1 - projectName : This is a string object . In the HTML , project name will be entered here .
Arg2 - hintEerror : This is a jquery object which will accept span which throws error for
duplicate project
Arg3 - ctrlGrpValidateProjectName : This object holds the div with class "control-group"
Arg4 - enableOrDisableBtn : This object will help the API to enable or disable the form .
For example in the new project the create project button will be hidden if the
duplicate project exist . Similarly in the projecttopbar the save button will be
disabled if the project name already exist .
Return - This function doesn ' t return anything . It sets / unsets the behavior of the elements .
* /
function _makeProjectNameValidation ( projectName , hintError ,
ctrlGrpValidateProjectName , enableOrDisableBtn ) {
function checkProjectName ( projectName ) {
$ . ajax ( {
type : "GET" ,
url : libtoaster . ctx . projectsTypeAheadUrl ,
data : { 'search' : projectName } ,
headers : { 'X-CSRFToken' : $ . cookie ( 'csrftoken' ) } ,
success : function ( data ) {
if ( data . results . length > 0 &&
data . results [ 0 ] . name === projectName ) {
// This project name exists hence show the error and disable
// the save button
2016-04-12 14:56:43 +00:00
ctrlGrpValidateProjectName . addClass ( 'has-error' ) ;
2016-05-09 23:01:48 +00:00
hintError . show ( ) ;
enableOrDisableBtn . attr ( 'disabled' , 'disabled' ) ;
} else {
2016-04-12 14:56:43 +00:00
ctrlGrpValidateProjectName . removeClass ( 'has-error' ) ;
2016-05-09 23:01:48 +00:00
hintError . hide ( ) ;
enableOrDisableBtn . removeAttr ( 'disabled' ) ;
}
} ,
error : function ( data ) {
console . log ( data ) ;
} ,
} ) ;
}
/* The moment user types project name remove the error */
projectName . on ( "input" , function ( ) {
var projectName = $ ( this ) . val ( ) ;
checkProjectName ( projectName )
} ) ;
/* Validate new project name */
projectName . on ( "blur" , function ( ) {
var projectName = $ ( this ) . val ( ) ;
checkProjectName ( projectName )
} ) ;
}
2016-07-15 14:20:36 +00:00
// if true, the loading spinner for Ajax requests will be displayed
// if requests take more than 1200ms
var ajaxLoadingTimerEnabled = true ;
// turn on the page-level loading spinner for Ajax requests
function _enableAjaxLoadingTimer ( ) {
ajaxLoadingTimerEnabled = true ;
}
// turn off the page-level loading spinner for Ajax requests
function _disableAjaxLoadingTimer ( ) {
ajaxLoadingTimerEnabled = false ;
}
2015-01-14 12:46:52 +00:00
2016-09-26 10:59:30 +00:00
/* Utility function to set a notification for the next page load */
function _setNotification ( name , message ) {
var data = {
name : name ,
message : message
} ;
$ . cookie ( 'toaster-notification' , JSON . stringify ( data ) , { path : '/' } ) ;
}
2014-11-11 16:23:58 +00:00
return {
2016-07-15 14:20:36 +00:00
enableAjaxLoadingTimer : _enableAjaxLoadingTimer ,
disableAjaxLoadingTimer : _disableAjaxLoadingTimer ,
2014-11-11 16:23:58 +00:00
reload _params : reload _params ,
startABuild : _startABuild ,
2015-03-13 14:34:41 +00:00
cancelABuild : _cancelABuild ,
bitbake: toaster: move most recent builds templating to client
The most recent builds area of the all builds and project builds
table needs to update as a build progresses. It also needs
additional functionality to show other states (e.g. recipe parsing,
queued) which again needs to update on the client side.
Rather than add to the existing mix of server-side templating
with client-side DOM updating, translate all of the server-side
templates to client-side ones (jsrender), and add logic which
updates the most recent builds area as the state of a build changes.
Add a JSON API for mostrecentbuilds, which returns the state of
all "recent" builds. Fetch this via Ajax from the build dashboard
(rather than fetching the ad hoc API as in the previous version).
Then, as new states for builds are fetched via Ajax, determine
whether the build state has changed completely, or whether the progress
has just updated. If the state completely changed, re-render the
template on the client side for that build. If only the progress
changed, just update the progress bar. (NB this fixes the
task progress bar so it works for the project builds and all builds
pages.)
In cases where the builds table needs to update as the result of
a build finishing, reload the whole page.
This work highlighted a variety of other issues, such as
build requests not being able to change state as necessary. This
was one part of the cause of the "cancelling build..." state
being fragile and disappearing entirely when the page refreshed.
The cancelling state now persists between page reloads, as the
logic for determining whether a build is cancelling is now on
the Build object itself.
Note that jsrender is redistributed as part of Toaster, so
a note was added to LICENSE to that effect.
[YOCTO #9631]
(Bitbake rev: c868ea036aa34b387a72ec5116a66b2cd863995b)
Signed-off-by: Elliot Smith <elliot.smith@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2016-06-29 14:41:56 +00:00
getMostRecentBuilds : _getMostRecentBuilds ,
2014-11-11 16:23:58 +00:00
makeTypeahead : _makeTypeahead ,
2014-11-14 18:12:20 +00:00
getProjectInfo : _getProjectInfo ,
2014-11-26 15:06:47 +00:00
getLayerDepsForProject : _getLayerDepsForProject ,
2015-04-10 17:15:03 +00:00
editCurrentProject : _editCurrentProject ,
2015-01-08 13:15:10 +00:00
debug : false ,
2015-01-14 12:46:52 +00:00
parseUrlParams : _parseUrlParams ,
dumpsUrlParams : _dumpsUrlParams ,
2015-04-21 10:59:37 +00:00
addRmLayer : _addRmLayer ,
makeLayerAddRmAlertMsg : _makeLayerAddRmAlertMsg ,
2015-07-31 12:09:08 +00:00
showChangeNotification : _showChangeNotification ,
2015-12-07 18:43:15 +00:00
createCustomRecipe : _createCustomRecipe ,
2016-05-09 23:01:48 +00:00
makeProjectNameValidation : _makeProjectNameValidation ,
2016-09-26 10:59:30 +00:00
setNotification : _setNotification ,
2015-03-03 16:18:24 +00:00
} ;
2014-11-11 16:23:58 +00:00
} ) ( ) ;
/* keep this in the global scope for compatability */
function reload _params ( params ) {
2015-03-03 16:18:24 +00:00
var uri = window . location . href ;
var splitlist = uri . split ( "?" ) ;
var url = splitlist [ 0 ] ;
var parameters = splitlist [ 1 ] ;
2014-11-11 16:23:58 +00:00
// deserialize the call parameters
2015-03-03 16:18:24 +00:00
var cparams = [ ] ;
if ( parameters )
cparams = parameters . split ( "&" ) ;
var nparams = { } ;
for ( var i = 0 ; i < cparams . length ; i ++ ) {
var temp = cparams [ i ] . split ( "=" ) ;
2014-11-11 16:23:58 +00:00
nparams [ temp [ 0 ] ] = temp [ 1 ] ;
}
// update parameter values
for ( i in params ) {
nparams [ encodeURIComponent ( i ) ] = encodeURIComponent ( params [ i ] ) ;
}
// serialize the structure
2015-03-03 16:18:24 +00:00
var callparams = [ ] ;
2014-11-11 16:23:58 +00:00
for ( i in nparams ) {
callparams . push ( i + "=" + nparams [ i ] ) ;
}
window . location . href = url + "?" + callparams . join ( '&' ) ;
}
/* Things that happen for all pages */
$ ( document ) . ready ( function ( ) {
2016-09-26 10:59:30 +00:00
( function showNotificationRequest ( ) {
var cookie = $ . cookie ( 'toaster-notification' ) ;
if ( ! cookie )
return ;
var notificationData = JSON . parse ( cookie ) ;
libtoaster . showChangeNotification ( notificationData . message ) ;
$ . removeCookie ( 'toaster-notification' , { path : "/" } ) ;
} ) ( ) ;
2015-05-21 17:44:18 +00:00
var ajaxLoadingTimer ;
2015-03-03 16:18:24 +00:00
/ * I f w e d o n ' t h a v e a c o n s o l e o b j e c t w h i c h m i g h t b e t h e c a s e i n s o m e
2015-01-08 13:15:10 +00:00
* browsers , no - op it to avoid undefined errors .
* /
if ( ! window . console ) {
window . console = { } ;
window . console . warn = function ( ) { } ;
window . console . error = function ( ) { } ;
}
2014-11-11 16:23:58 +00:00
/ *
2017-10-10 03:31:40 +00:00
* highlight plugin .
2014-11-11 16:23:58 +00:00
* /
2017-10-10 03:31:40 +00:00
hljs . initHighlightingOnLoad ( ) ;
2014-11-11 16:23:58 +00:00
// Prevent invalid links from jumping page scroll
$ ( 'a[href=#]' ) . click ( function ( ) {
return false ;
} ) ;
2015-05-11 17:51:28 +00:00
/* START TODO Delete this section now redundant */
2014-11-11 16:23:58 +00:00
/* Belen's additions */
// turn Edit columns dropdown into a multiselect menu
$ ( '.dropdown-menu input, .dropdown-menu label' ) . click ( function ( e ) {
e . stopPropagation ( ) ;
} ) ;
// enable popovers in any table cells that contain an anchor with the
// .btn class applied, and make sure popovers work on click, are mutually
// exclusive and they close when your click outside their area
2015-03-03 16:18:24 +00:00
$ ( 'html' ) . click ( function ( ) {
2014-11-11 16:23:58 +00:00
$ ( 'td > a.btn' ) . popover ( 'hide' ) ;
} ) ;
$ ( 'td > a.btn' ) . popover ( {
html : true ,
placement : 'left' ,
container : 'body' ,
trigger : 'manual'
} ) . click ( function ( e ) {
$ ( 'td > a.btn' ) . not ( this ) . popover ( 'hide' ) ;
// ideally we would use 'toggle' here
// but it seems buggy in our Bootstrap version
$ ( this ) . popover ( 'show' ) ;
e . stopPropagation ( ) ;
} ) ;
// enable tooltips for applied filters
$ ( 'th a.btn-primary' ) . tooltip ( { container : 'body' , html : true , placement : 'bottom' , delay : { hide : 1500 } } ) ;
// hide applied filter tooltip when you click on the filter button
$ ( 'th a.btn-primary' ) . click ( function ( ) {
$ ( '.tooltip' ) . hide ( ) ;
} ) ;
2016-02-10 00:05:07 +00:00
/* Initialise bootstrap tooltips */
$ ( ".get-help, [data-toggle=tooltip]" ) . tooltip ( {
container : 'body' ,
html : true ,
delay : { show : 300 }
} ) ;
2014-11-11 16:23:58 +00:00
2016-06-02 13:26:16 +00:00
// show help bubble on hover inside tables
2016-01-15 11:00:48 +00:00
$ ( "table" ) . on ( "mouseover" , "th, td" , function ( ) {
2014-11-11 16:23:58 +00:00
$ ( this ) . find ( ".hover-help" ) . css ( "visibility" , "visible" ) ;
} ) ;
2016-01-15 11:00:48 +00:00
$ ( "table" ) . on ( "mouseleave" , "th, td" , function ( ) {
2014-11-11 16:23:58 +00:00
$ ( this ) . find ( ".hover-help" ) . css ( "visibility" , "hidden" ) ;
} ) ;
2015-05-11 17:51:28 +00:00
/* END TODO Delete this section now redundant */
2014-11-11 16:23:58 +00:00
// show task type and outcome in task details pages
$ ( ".task-info" ) . tooltip ( { container : 'body' , html : true , delay : { show : 200 } , placement : 'right' } ) ;
2016-04-12 14:56:43 +00:00
// initialise the tooltips for the edit icons
$ ( ".glyphicon-edit" ) . tooltip ( { container : 'body' , html : true , delay : { show : 400 } , title : "Change" } ) ;
2014-12-03 13:57:30 +00:00
2015-02-09 11:48:39 +00:00
// initialise the tooltips for the download icons
$ ( ".icon-download-alt" ) . tooltip ( { container : 'body' , html : true , delay : { show : 200 } } ) ;
2015-02-24 17:20:53 +00:00
// initialise popover for debug information
2016-04-12 14:56:43 +00:00
$ ( ".glyphicon-info-sign" ) . popover ( { placement : 'bottom' , html : true , container : 'body' } ) ;
2015-02-24 17:20:53 +00:00
2014-11-11 16:23:58 +00:00
// linking directly to tabs
$ ( function ( ) {
var hash = window . location . hash ;
2015-03-03 16:18:24 +00:00
$ ( 'ul.nav a[href="' + hash + '"]' ) . tab ( 'show' ) ;
2014-11-11 16:23:58 +00:00
2015-03-03 16:18:24 +00:00
$ ( '.nav-tabs a' ) . click ( function ( ) {
2014-11-11 16:23:58 +00:00
$ ( this ) . tab ( 'show' ) ;
$ ( 'body' ) . scrollTop ( ) ;
} ) ;
} ) ;
// toggle for long content (variables, python stack trace, etc)
$ ( '.full, .full-hide' ) . hide ( ) ;
$ ( '.full-show' ) . click ( function ( ) {
$ ( '.full' ) . slideDown ( function ( ) {
$ ( '.full-hide' ) . show ( ) ;
} ) ;
$ ( this ) . hide ( ) ;
} ) ;
$ ( '.full-hide' ) . click ( function ( ) {
$ ( this ) . hide ( ) ;
$ ( '.full' ) . slideUp ( function ( ) {
$ ( '.full-show' ) . show ( ) ;
} ) ;
} ) ;
//toggle the errors and warnings sections
$ ( '.show-errors' ) . click ( function ( ) {
$ ( '#collapse-errors' ) . addClass ( 'in' ) ;
} ) ;
$ ( '.toggle-errors' ) . click ( function ( ) {
$ ( '#collapse-errors' ) . toggleClass ( 'in' ) ;
} ) ;
$ ( '.show-warnings' ) . click ( function ( ) {
$ ( '#collapse-warnings' ) . addClass ( 'in' ) ;
} ) ;
$ ( '.toggle-warnings' ) . click ( function ( ) {
$ ( '#collapse-warnings' ) . toggleClass ( 'in' ) ;
} ) ;
2014-11-25 10:12:46 +00:00
$ ( '.show-exceptions' ) . click ( function ( ) {
$ ( '#collapse-exceptions' ) . addClass ( 'in' ) ;
} ) ;
$ ( '.toggle-exceptions' ) . click ( function ( ) {
$ ( '#collapse-exceptions' ) . toggleClass ( 'in' ) ;
} ) ;
2015-04-21 10:59:37 +00:00
$ ( "#hide-alert" ) . click ( function ( ) {
$ ( this ) . parent ( ) . fadeOut ( ) ;
} ) ;
2014-11-11 16:23:58 +00:00
//show warnings section when requested from the previous page
if ( location . href . search ( '#warnings' ) > - 1 ) {
$ ( '#collapse-warnings' ) . addClass ( 'in' ) ;
}
2015-01-08 13:15:10 +00:00
2015-05-21 17:44:18 +00:00
/ * S h o w t h e l o a d i n g n o t i f i c a t i o n i f n o t h i n g h a s h a p p e n d a f t e r 1 . 5
* seconds
* /
$ ( document ) . bind ( "ajaxStart" , function ( ) {
if ( ajaxLoadingTimer )
window . clearTimeout ( ajaxLoadingTimer ) ;
ajaxLoadingTimer = window . setTimeout ( function ( ) {
2016-07-15 14:20:36 +00:00
if ( libtoaster . ajaxLoadingTimerEnabled ) {
$ ( "#loading-notification" ) . fadeIn ( ) ;
}
2015-05-21 17:44:18 +00:00
} , 1200 ) ;
} ) ;
$ ( document ) . bind ( "ajaxStop" , function ( ) {
if ( ajaxLoadingTimer )
window . clearTimeout ( ajaxLoadingTimer ) ;
$ ( "#loading-notification" ) . fadeOut ( ) ;
} ) ;
2015-05-21 17:45:44 +00:00
$ ( document ) . ajaxError ( function ( event , jqxhr , settings , errMsg ) {
2015-08-04 19:46:39 +00:00
if ( errMsg === 'abort' )
return ;
2015-05-21 17:45:44 +00:00
console . warn ( "Problem with xhr call" ) ;
console . warn ( errMsg ) ;
console . warn ( jqxhr . responseText ) ;
} ) ;
2015-05-21 17:44:18 +00:00
2015-01-08 13:15:10 +00:00
function check _for _duplicate _ids ( ) {
/* warn about duplicate element ids */
var ids = { } ;
$ ( "[id]" ) . each ( function ( ) {
if ( this . id && ids [ this . id ] ) {
console . warn ( 'Duplicate element id #' + this . id ) ;
}
ids [ this . id ] = true ;
} ) ;
}
2016-09-26 10:59:32 +00:00
/* Make sure we don't have a notification overlay a modal */
$ ( ".modal" ) . on ( 'show.bs.modal' , function ( ) {
$ ( ".alert-dismissible" ) . fadeOut ( ) ;
} ) ;
2015-01-08 13:15:10 +00:00
if ( libtoaster . debug ) {
check _for _duplicate _ids ( ) ;
} else {
/* Debug is false so supress warnings by overriding the functions */
window . console . warn = function ( ) { } ;
window . console . error = function ( ) { } ;
}
2014-11-11 16:23:58 +00:00
} ) ;