2015-09-28 15:07:37 +00:00
( function ( global , factory ) {
if ( typeof define === "function" && define . amd ) {
2017-01-20 10:34:19 +00:00
define ( [ "OctoPrintClient" ] , factory ) ;
2015-09-28 15:07:37 +00:00
} else {
2017-01-20 10:34:19 +00:00
factory ( global . OctoPrintClient ) ;
2015-09-28 15:07:37 +00:00
}
2017-01-20 10:34:19 +00:00
} ) ( this , function ( OctoPrintClient ) {
var OctoPrintPluginManagerClient = function ( base ) {
this . base = base ;
} ;
2015-09-28 15:07:37 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . get = function ( refresh , opts ) {
2017-03-31 14:52:48 +00:00
var refresh _repo , refresh _notices ;
if ( _ . isPlainObject ( refresh ) ) {
refresh _repo = refresh . repo || false ;
refresh _notices = refresh . notices || false ;
} else {
refresh _repo = refresh ;
refresh _notices = false ;
}
var query = [ ] ;
if ( refresh _repo ) query . push ( "refresh_repository=true" ) ;
if ( refresh _notices ) query . push ( "refresh_notices=true" ) ;
return this . base . get ( this . base . getSimpleApiUrl ( "pluginmanager" ) + ( ( query . length ) ? "?" + query . join ( "&" ) : "" ) , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . getWithRefresh = function ( opts ) {
return this . get ( true , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . getWithoutRefresh = function ( opts ) {
return this . get ( false , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . install = function ( pluginUrl , dependencyLinks , opts ) {
2015-09-28 15:07:37 +00:00
var data = {
url : pluginUrl ,
dependency _links : ! ! dependencyLinks
2015-09-25 11:53:42 +00:00
} ;
2017-01-20 10:34:19 +00:00
return this . base . simpleApiCommand ( "pluginmanager" , "install" , data , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . reinstall = function ( plugin , pluginUrl , dependencyLinks , opts ) {
2015-09-28 15:07:37 +00:00
var data = {
url : pluginUrl ,
dependency _links : ! ! dependencyLinks ,
reinstall : plugin ,
force : true
2015-09-25 11:53:42 +00:00
} ;
2017-01-20 10:34:19 +00:00
return this . base . simpleApiCommand ( "pluginmanager" , "install" , data , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2015-09-25 11:53:42 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . uninstall = function ( plugin , opts ) {
2015-09-28 15:07:37 +00:00
var data = {
plugin : plugin
2015-09-25 11:53:42 +00:00
} ;
2017-01-20 10:34:19 +00:00
return this . base . simpleApiCommand ( "pluginmanager" , "uninstall" , data , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2015-09-25 11:53:42 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . enable = function ( plugin , opts ) {
2015-09-28 15:07:37 +00:00
var data = {
plugin : plugin
2015-09-25 11:53:42 +00:00
} ;
2017-01-20 10:34:19 +00:00
return this . base . simpleApiCommand ( "pluginmanager" , "enable" , data , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2015-09-25 11:53:42 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . disable = function ( plugin , opts ) {
2015-09-28 15:07:37 +00:00
var data = {
plugin : plugin
2015-09-25 11:53:42 +00:00
} ;
2017-01-20 10:34:19 +00:00
return this . base . simpleApiCommand ( "pluginmanager" , "disable" , data , opts ) ;
2015-09-28 15:07:37 +00:00
} ;
2015-09-25 11:53:42 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintPluginManagerClient . prototype . upload = function ( file ) {
return this . base . upload ( this . base . getBlueprintUrl ( "pluginmanager" ) + "upload_archive" , file ) ;
2015-09-28 15:07:37 +00:00
} ;
2015-09-25 11:53:42 +00:00
2017-01-20 10:34:19 +00:00
OctoPrintClient . registerPluginComponent ( "pluginmanager" , OctoPrintPluginManagerClient ) ;
return OctoPrintPluginManagerClient ;
2015-09-28 15:07:37 +00:00
} ) ;
2015-09-25 11:53:42 +00:00
2015-09-28 15:07:37 +00:00
$ ( function ( ) {
2015-05-29 14:31:43 +00:00
function PluginManagerViewModel ( parameters ) {
var self = this ;
self . loginState = parameters [ 0 ] ;
self . settingsViewModel = parameters [ 1 ] ;
2015-06-18 09:37:08 +00:00
self . printerState = parameters [ 2 ] ;
2015-10-01 12:20:37 +00:00
self . systemViewModel = parameters [ 3 ] ;
2015-05-29 14:31:43 +00:00
2015-09-22 09:36:57 +00:00
self . config _repositoryUrl = ko . observable ( ) ;
self . config _repositoryTtl = ko . observable ( ) ;
2017-03-31 14:52:48 +00:00
self . config _noticesUrl = ko . observable ( ) ;
self . config _noticesTtl = ko . observable ( ) ;
2015-09-28 17:53:30 +00:00
self . config _pipAdditionalArgs = ko . observable ( ) ;
2015-09-30 11:36:00 +00:00
self . config _pipForceUser = ko . observable ( ) ;
2015-09-22 09:36:57 +00:00
self . configurationDialog = $ ( "#settings_plugin_pluginmanager_configurationdialog" ) ;
2015-05-29 14:31:43 +00:00
self . plugins = new ItemListHelper (
"plugin.pluginmanager.installedplugins" ,
{
"name" : function ( a , b ) {
// sorts ascending
if ( a [ "name" ] . toLocaleLowerCase ( ) < b [ "name" ] . toLocaleLowerCase ( ) ) return - 1 ;
if ( a [ "name" ] . toLocaleLowerCase ( ) > b [ "name" ] . toLocaleLowerCase ( ) ) return 1 ;
return 0 ;
}
} ,
{
} ,
"name" ,
[ ] ,
[ ] ,
5
) ;
self . repositoryplugins = new ItemListHelper (
"plugin.pluginmanager.repositoryplugins" ,
{
"title" : function ( a , b ) {
// sorts ascending
if ( a [ "title" ] . toLocaleLowerCase ( ) < b [ "title" ] . toLocaleLowerCase ( ) ) return - 1 ;
if ( a [ "title" ] . toLocaleLowerCase ( ) > b [ "title" ] . toLocaleLowerCase ( ) ) return 1 ;
return 0 ;
} ,
"published" : function ( a , b ) {
// sorts descending
if ( a [ "published" ] . toLocaleLowerCase ( ) > b [ "published" ] . toLocaleLowerCase ( ) ) return - 1 ;
if ( a [ "published" ] . toLocaleLowerCase ( ) < b [ "published" ] . toLocaleLowerCase ( ) ) return 1 ;
return 0 ;
}
} ,
{
"filter_installed" : function ( plugin ) {
return ! self . installed ( plugin ) ;
} ,
"filter_incompatible" : function ( plugin ) {
return plugin . is _compatible . octoprint && plugin . is _compatible . os ;
}
} ,
"title" ,
[ "filter_installed" , "filter_incompatible" ] ,
[ ] ,
0
) ;
self . uploadElement = $ ( "#settings_plugin_pluginmanager_repositorydialog_upload" ) ;
self . uploadButton = $ ( "#settings_plugin_pluginmanager_repositorydialog_upload_start" ) ;
self . repositoryAvailable = ko . observable ( false ) ;
self . repositorySearchQuery = ko . observable ( ) ;
self . repositorySearchQuery . subscribe ( function ( ) {
self . performRepositorySearch ( ) ;
} ) ;
self . installUrl = ko . observable ( ) ;
self . uploadFilename = ko . observable ( ) ;
self . loglines = ko . observableArray ( [ ] ) ;
self . installedPlugins = ko . observableArray ( [ ] ) ;
2015-07-22 14:57:32 +00:00
self . followDependencyLinks = ko . observable ( false ) ;
2015-09-22 09:36:57 +00:00
self . pipAvailable = ko . observable ( false ) ;
self . pipVersion = ko . observable ( ) ;
2015-09-29 12:51:58 +00:00
self . pipInstallDir = ko . observable ( ) ;
self . pipUseUser = ko . observable ( ) ;
2015-09-30 11:36:45 +00:00
self . pipVirtualEnv = ko . observable ( ) ;
2015-09-28 17:53:30 +00:00
self . pipAdditionalArgs = ko . observable ( ) ;
2016-02-11 08:38:35 +00:00
self . pipPython = ko . observable ( ) ;
2015-09-22 09:36:57 +00:00
2016-11-18 12:01:14 +00:00
self . safeMode = ko . observable ( ) ;
2016-01-27 16:36:39 +00:00
self . pipUseUserString = ko . pureComputed ( function ( ) {
2015-09-29 12:51:58 +00:00
return self . pipUseUser ( ) ? "yes" : "no" ;
} ) ;
2016-01-27 16:36:39 +00:00
self . pipVirtualEnvString = ko . pureComputed ( function ( ) {
2015-09-30 11:36:45 +00:00
return self . pipVirtualEnv ( ) ? "yes" : "no" ;
} ) ;
2015-09-22 09:36:57 +00:00
2015-05-29 14:31:43 +00:00
self . working = ko . observable ( false ) ;
self . workingTitle = ko . observable ( ) ;
self . workingDialog = undefined ;
self . workingOutput = undefined ;
2015-10-01 12:20:37 +00:00
self . restartCommandSpec = undefined ;
self . systemViewModel . systemActions . subscribe ( function ( ) {
var lastResponse = self . systemViewModel . lastCommandResponse ;
if ( ! lastResponse || ! lastResponse . core ) {
self . restartCommandSpec = undefined ;
return ;
}
var restartSpec = _ . filter ( lastResponse . core , function ( spec ) { return spec . action == "restart" } ) ;
self . restartCommandSpec = restartSpec != undefined && restartSpec . length > 0 ? restartSpec [ 0 ] : undefined ;
} ) ;
self . notifications = [ ] ;
2017-03-31 14:52:48 +00:00
self . noticeNotifications = [ ] ;
self . hiddenNoticeNotifications = { } ;
self . noticeCount = ko . observable ( 0 ) ;
self . noticeCountText = ko . pureComputed ( function ( ) {
var count = self . noticeCount ( ) ;
if ( count == 0 ) {
return gettext ( "There are no plugin notices. Great!" ) ;
} else if ( count == 1 ) {
return gettext ( "There is a plugin notice for one of your installed plugins." ) ;
} else {
return _ . sprintf ( gettext ( "There are %(count)d plugin notices for one or more of your installed plugins." ) , { count : count } ) ;
}
} ) ;
2015-10-01 12:20:37 +00:00
2016-01-27 16:33:03 +00:00
self . enableManagement = ko . pureComputed ( function ( ) {
2015-06-18 09:37:08 +00:00
return ! self . printerState . isPrinting ( ) ;
} ) ;
self . enableToggle = function ( data ) {
2016-11-18 12:01:14 +00:00
var command = self . _getToggleCommand ( data ) ;
return self . enableManagement ( ) && ( command == "disable" || ! data . safe _mode _victim || data . safe _mode _enabled ) && data . key != 'pluginmanager' ;
2015-06-18 09:37:08 +00:00
} ;
self . enableUninstall = function ( data ) {
2015-09-22 09:36:57 +00:00
return self . enableManagement ( )
&& ( data . origin != "entry_point" || self . pipAvailable ( ) )
2015-09-30 11:44:58 +00:00
&& data . managable
2015-09-22 09:36:57 +00:00
&& ! data . bundled
&& data . key != 'pluginmanager'
&& ! data . pending _uninstall ;
2015-06-18 09:37:08 +00:00
} ;
self . enableRepoInstall = function ( data ) {
2016-11-18 12:01:14 +00:00
return self . enableManagement ( ) && self . pipAvailable ( ) && ! self . safeMode ( ) && self . isCompatible ( data ) ;
2015-06-18 09:37:08 +00:00
} ;
2016-01-27 16:33:03 +00:00
self . invalidUrl = ko . pureComputed ( function ( ) {
2015-05-29 14:31:43 +00:00
var url = self . installUrl ( ) ;
return url !== undefined && url . trim ( ) != "" && ! ( _ . startsWith ( url . toLocaleLowerCase ( ) , "http://" ) || _ . startsWith ( url . toLocaleLowerCase ( ) , "https://" ) ) ;
} ) ;
2016-01-27 16:33:03 +00:00
self . enableUrlInstall = ko . pureComputed ( function ( ) {
2015-05-29 14:31:43 +00:00
var url = self . installUrl ( ) ;
2016-11-18 12:01:14 +00:00
return self . enableManagement ( ) && self . pipAvailable ( ) && ! self . safeMode ( ) && url !== undefined && url . trim ( ) != "" && ! self . invalidUrl ( ) ;
2015-05-29 14:31:43 +00:00
} ) ;
2016-01-27 16:33:03 +00:00
self . invalidArchive = ko . pureComputed ( function ( ) {
2015-05-29 14:31:43 +00:00
var name = self . uploadFilename ( ) ;
return name !== undefined && ! ( _ . endsWith ( name . toLocaleLowerCase ( ) , ".zip" ) || _ . endsWith ( name . toLocaleLowerCase ( ) , ".tar.gz" ) || _ . endsWith ( name . toLocaleLowerCase ( ) , ".tgz" ) || _ . endsWith ( name . toLocaleLowerCase ( ) , ".tar" ) ) ;
} ) ;
2016-01-27 16:33:03 +00:00
self . enableArchiveInstall = ko . pureComputed ( function ( ) {
2015-05-29 14:31:43 +00:00
var name = self . uploadFilename ( ) ;
2016-11-18 12:01:14 +00:00
return self . enableManagement ( ) && self . pipAvailable ( ) && ! self . safeMode ( ) && name !== undefined && name . trim ( ) != "" && ! self . invalidArchive ( ) ;
2015-05-29 14:31:43 +00:00
} ) ;
self . uploadElement . fileupload ( {
dataType : "json" ,
maxNumberOfFiles : 1 ,
autoUpload : false ,
add : function ( e , data ) {
if ( data . files . length == 0 ) {
return false ;
}
self . uploadFilename ( data . files [ 0 ] . name ) ;
self . uploadButton . unbind ( "click" ) ;
self . uploadButton . bind ( "click" , function ( ) {
self . _markWorking ( gettext ( "Installing plugin..." ) , gettext ( "Installing plugin from uploaded archive..." ) ) ;
2015-07-22 14:57:32 +00:00
data . formData = {
dependency _links : self . followDependencyLinks ( )
} ;
2015-05-29 14:31:43 +00:00
data . submit ( ) ;
return false ;
} ) ;
} ,
done : function ( e , data ) {
2017-04-04 13:18:37 +00:00
var response = data . result ;
if ( response . result ) {
self . _markDone ( ) ;
} else {
self . _markDone ( response . reason ) ;
}
2015-05-29 14:31:43 +00:00
self . uploadButton . unbind ( "click" ) ;
2016-11-21 15:25:53 +00:00
self . uploadFilename ( undefined ) ;
2015-05-29 14:31:43 +00:00
} ,
fail : function ( e , data ) {
new PNotify ( {
title : gettext ( "Something went wrong" ) ,
text : gettext ( "Please consult octoprint.log for details" ) ,
type : "error" ,
hide : false
} ) ;
2017-04-04 13:18:37 +00:00
self . _markDone ( "Could not install plugin, unknown error." ) ;
2015-05-29 14:31:43 +00:00
self . uploadButton . unbind ( "click" ) ;
2016-11-21 15:25:53 +00:00
self . uploadFilename ( undefined ) ;
2015-05-29 14:31:43 +00:00
}
} ) ;
2015-07-08 06:45:36 +00:00
self . performRepositorySearch = function ( ) {
2015-05-29 14:31:43 +00:00
var query = self . repositorySearchQuery ( ) ;
if ( query !== undefined && query . trim ( ) != "" ) {
2015-07-08 06:45:36 +00:00
query = query . toLocaleLowerCase ( ) ;
2015-05-29 14:31:43 +00:00
self . repositoryplugins . changeSearchFunction ( function ( entry ) {
return entry && ( entry [ "title" ] . toLocaleLowerCase ( ) . indexOf ( query ) > - 1 || entry [ "description" ] . toLocaleLowerCase ( ) . indexOf ( query ) > - 1 ) ;
} ) ;
} else {
self . repositoryplugins . resetSearch ( ) ;
}
2015-07-07 21:24:27 +00:00
return false ;
2015-05-29 14:31:43 +00:00
} ;
2017-03-31 14:52:48 +00:00
self . fromResponse = function ( data , options ) {
self . _fromPluginsResponse ( data . plugins , options ) ;
self . _fromRepositoryResponse ( data . repository , options ) ;
self . _fromPipResponse ( data . pip , options ) ;
2016-11-18 12:01:14 +00:00
self . safeMode ( data . safe _mode || false ) ;
2015-05-29 14:31:43 +00:00
} ;
2017-03-31 14:52:48 +00:00
self . _fromPluginsResponse = function ( data , options ) {
var evalNotices = options . eval _notices || false ;
var ignoreNoticeHidden = options . ignore _notice _hidden || false ;
var ignoreNoticeIgnored = options . ignore _notice _ignored || false ;
if ( evalNotices ) self . _removeAllNoticeNotifications ( ) ;
2015-05-29 14:31:43 +00:00
var installedPlugins = [ ] ;
2017-03-31 14:52:48 +00:00
var noticeCount = 0 ;
2015-05-29 14:31:43 +00:00
_ . each ( data , function ( plugin ) {
installedPlugins . push ( plugin . key ) ;
2017-03-31 14:52:48 +00:00
if ( evalNotices && plugin . notifications && plugin . notifications . length ) {
_ . each ( plugin . notifications , function ( notification ) {
noticeCount ++ ;
if ( ! ignoreNoticeIgnored && self . _isNoticeNotificationIgnored ( plugin . key , notification . date ) ) return ;
if ( ! ignoreNoticeHidden && self . _isNoticeNotificationHidden ( plugin . key , notification . date ) ) return ;
self . _showPluginNotification ( plugin , notification ) ;
} ) ;
}
2015-05-29 14:31:43 +00:00
} ) ;
2017-03-31 14:52:48 +00:00
if ( evalNotices ) self . noticeCount ( noticeCount ) ;
2015-05-29 14:31:43 +00:00
self . installedPlugins ( installedPlugins ) ;
self . plugins . updateItems ( data ) ;
} ;
self . _fromRepositoryResponse = function ( data ) {
self . repositoryAvailable ( data . available ) ;
if ( data . available ) {
self . repositoryplugins . updateItems ( data . plugins ) ;
} else {
self . repositoryplugins . updateItems ( [ ] ) ;
}
} ;
2015-09-22 09:36:57 +00:00
self . _fromPipResponse = function ( data ) {
self . pipAvailable ( data . available ) ;
if ( data . available ) {
self . pipVersion ( data . version ) ;
2015-09-29 12:51:58 +00:00
self . pipInstallDir ( data . install _dir ) ;
self . pipUseUser ( data . use _user ) ;
2015-09-30 11:36:45 +00:00
self . pipVirtualEnv ( data . virtual _env ) ;
2015-09-28 17:53:30 +00:00
self . pipAdditionalArgs ( data . additional _args ) ;
2016-02-11 08:38:35 +00:00
self . pipPython ( data . python ) ;
2015-09-22 09:36:57 +00:00
} else {
self . pipVersion ( undefined ) ;
2015-09-29 12:51:58 +00:00
self . pipInstallDir ( undefined ) ;
2015-09-30 11:36:45 +00:00
self . pipUseUser ( undefined ) ;
self . pipVirtualEnv ( undefined ) ;
2015-09-28 17:53:30 +00:00
self . pipAdditionalArgs ( undefined ) ;
2015-09-22 09:36:57 +00:00
}
} ;
2017-03-31 14:52:48 +00:00
self . requestData = function ( options ) {
2015-05-29 14:31:43 +00:00
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2017-03-31 14:52:48 +00:00
if ( ! _ . isPlainObject ( options ) ) {
options = {
refresh _repo : options ,
refresh _notices : false ,
eval _notices : false
} ;
}
options . refresh _repo = options . refresh _repo || false ;
options . refresh _notices = options . refresh _notices || false ;
options . eval _notices = options . eval _notices || false ;
OctoPrint . plugins . pluginmanager . get ( { repo : options . refresh _repo , notices : options . refresh _notices } )
. done ( function ( data ) {
self . fromResponse ( data , options ) ;
} ) ;
2015-05-29 14:31:43 +00:00
} ;
self . togglePlugin = function ( data ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2015-06-18 09:37:08 +00:00
if ( ! self . enableManagement ( ) ) {
return ;
}
2015-05-29 14:31:43 +00:00
if ( data . key == "pluginmanager" ) return ;
2017-03-31 14:52:48 +00:00
var onSuccess = function ( ) {
self . requestData ( ) ;
} ,
2015-09-25 11:53:42 +00:00
onError = function ( ) {
new PNotify ( {
title : gettext ( "Something went wrong" ) ,
text : gettext ( "Please consult octoprint.log for details" ) ,
type : "error" ,
hide : false
} )
} ;
2015-05-29 14:31:43 +00:00
2015-09-25 11:53:42 +00:00
if ( self . _getToggleCommand ( data ) == "enable" ) {
2016-11-18 12:01:14 +00:00
if ( data . safe _mode _victim && ! data . safe _mode _enabled ) return ;
2015-09-25 11:53:42 +00:00
OctoPrint . plugins . pluginmanager . enable ( data . key )
. done ( onSuccess )
. fail ( onError ) ;
} else {
2017-03-30 12:08:47 +00:00
var perform = function ( ) {
OctoPrint . plugins . pluginmanager . disable ( data . key )
. done ( onSuccess )
. fail ( onError ) ;
} ;
if ( data . disabling _discouraged ) {
var message = _ . sprintf ( gettext ( "You are about to disable \"%(name)s\"." ) , { name : data . name } )
+ "</p><p>" + data . disabling _discouraged ;
showConfirmationDialog ( {
title : gettext ( "This is not recommended" ) ,
message : message ,
question : gettext ( "Do you still want to disable it?" ) ,
cancel : gettext ( "Keep enabled" ) ,
proceed : gettext ( "Disable anyway" ) ,
onproceed : perform
} )
} else {
perform ( ) ;
}
2015-09-25 11:53:42 +00:00
}
2015-05-29 14:31:43 +00:00
} ;
self . showRepository = function ( ) {
self . repositoryDialog . modal ( "show" ) ;
} ;
self . pluginDetails = function ( data ) {
window . open ( data . page ) ;
} ;
self . installFromRepository = function ( data ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2015-06-18 09:37:08 +00:00
if ( ! self . enableManagement ( ) ) {
return ;
}
2015-09-25 11:53:42 +00:00
self . installPlugin ( data . archive , data . title , ( self . installed ( data ) ? data . id : undefined ) , data . follow _dependency _links || self . followDependencyLinks ( ) ) ;
2015-05-29 14:31:43 +00:00
} ;
2015-07-22 14:57:32 +00:00
self . installPlugin = function ( url , name , reinstall , followDependencyLinks ) {
2015-05-29 14:31:43 +00:00
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2015-06-18 09:37:08 +00:00
if ( ! self . enableManagement ( ) ) {
return ;
}
2015-05-29 14:31:43 +00:00
if ( url === undefined ) {
url = self . installUrl ( ) ;
}
if ( ! url ) return ;
2015-07-22 14:57:32 +00:00
if ( followDependencyLinks === undefined ) {
followDependencyLinks = self . followDependencyLinks ( ) ;
}
2015-05-29 14:31:43 +00:00
var workTitle , workText ;
if ( ! reinstall ) {
workTitle = gettext ( "Installing plugin..." ) ;
if ( name ) {
workText = _ . sprintf ( gettext ( "Installing plugin \"%(name)s\" from %(url)s..." ) , { url : url , name : name } ) ;
} else {
workText = _ . sprintf ( gettext ( "Installing plugin from %(url)s..." ) , { url : url } ) ;
}
} else {
workTitle = gettext ( "Reinstalling plugin..." ) ;
workText = _ . sprintf ( gettext ( "Reinstalling plugin \"%(name)s\" from %(url)s..." ) , { url : url , name : name } ) ;
}
self . _markWorking ( workTitle , workText ) ;
2017-04-04 13:18:37 +00:00
var onSuccess = function ( response ) {
if ( response . result ) {
self . _markDone ( ) ;
} else {
self . _markDone ( response . reason )
}
2015-09-25 11:53:42 +00:00
self . requestData ( ) ;
self . installUrl ( "" ) ;
} ,
onError = function ( ) {
2017-04-04 13:18:37 +00:00
self . _markDone ( "Could not install plugin, unknown error, please consult octoprint.log for details" ) ;
2015-09-25 11:53:42 +00:00
new PNotify ( {
title : gettext ( "Something went wrong" ) ,
text : gettext ( "Please consult octoprint.log for details" ) ,
type : "error" ,
hide : false
} ) ;
} ;
2015-05-29 14:31:43 +00:00
if ( reinstall ) {
2015-09-25 11:53:42 +00:00
OctoPrint . plugins . pluginmanager . reinstall ( reinstall , url , followDependencyLinks )
. done ( onSuccess )
2017-05-16 14:00:40 +00:00
. fail ( onError ) ;
2015-09-25 11:53:42 +00:00
} else {
OctoPrint . plugins . pluginmanager . install ( url , followDependencyLinks )
. done ( onSuccess )
2017-05-16 14:00:40 +00:00
. fail ( onError ) ;
2015-05-29 14:31:43 +00:00
}
} ;
self . uninstallPlugin = function ( data ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2015-06-18 09:37:08 +00:00
if ( ! self . enableManagement ( ) ) {
return ;
}
2015-05-29 14:31:43 +00:00
if ( data . bundled ) return ;
if ( data . key == "pluginmanager" ) return ;
self . _markWorking ( gettext ( "Uninstalling plugin..." ) , _ . sprintf ( gettext ( "Uninstalling plugin \"%(name)s\"" ) , { name : data . name } ) ) ;
2015-09-25 11:53:42 +00:00
OctoPrint . plugins . pluginmanager . uninstall ( data . key )
2017-03-31 14:52:48 +00:00
. done ( function ( ) {
self . requestData ( ) ;
} )
2015-09-25 11:53:42 +00:00
. fail ( function ( ) {
new PNotify ( {
title : gettext ( "Something went wrong" ) ,
text : gettext ( "Please consult octoprint.log for details" ) ,
type : "error" ,
hide : false
} ) ;
} )
. always ( function ( ) {
self . _markDone ( ) ;
2015-05-29 14:31:43 +00:00
} ) ;
} ;
self . refreshRepository = function ( ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2017-03-31 14:52:48 +00:00
self . requestData ( { refresh _repo : true } ) ;
} ;
self . refreshNotices = function ( ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
self . requestData ( { refresh _notices : true , eval _notices : true , ignore _notice _hidden : true , ignore _notice _ignored : true } ) ;
} ;
self . reshowNotices = function ( ) {
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
2015-05-29 14:31:43 +00:00
2017-03-31 14:52:48 +00:00
self . requestData ( { eval _notices : true , ignore _notice _hidden : true , ignore _notice _ignored : true } ) ;
2015-05-29 14:31:43 +00:00
} ;
2015-09-22 09:36:57 +00:00
self . showPluginSettings = function ( ) {
self . _copyConfig ( ) ;
self . configurationDialog . modal ( ) ;
} ;
self . savePluginSettings = function ( ) {
var repository = self . config _repositoryUrl ( ) ;
if ( repository != undefined && repository . trim ( ) == "" ) {
repository = null ;
}
var repositoryTtl ;
try {
repositoryTtl = parseInt ( self . config _repositoryTtl ( ) ) ;
} catch ( ex ) {
repositoryTtl = null ;
}
2017-03-31 14:52:48 +00:00
var notices = self . config _noticesUrl ( ) ;
if ( notices != undefined && notices . trim ( ) == "" ) {
notices = null ;
}
var noticesTtl ;
try {
noticesTtl = parseInt ( self . config _noticesTtl ( ) ) ;
} catch ( ex ) {
noticesTtl = null ;
}
2015-09-28 17:53:30 +00:00
var pipArgs = self . config _pipAdditionalArgs ( ) ;
if ( pipArgs != undefined && pipArgs . trim ( ) == "" ) {
pipArgs = null ;
}
2015-09-22 09:36:57 +00:00
var data = {
plugins : {
pluginmanager : {
repository : repository ,
repository _ttl : repositoryTtl ,
2017-03-31 14:52:48 +00:00
notices : notices ,
notices _ttl : noticesTtl ,
2015-09-30 11:36:00 +00:00
pip _args : pipArgs ,
pip _force _user : self . config _pipForceUser ( )
2015-09-22 09:36:57 +00:00
}
}
} ;
self . settingsViewModel . saveData ( data , function ( ) {
self . configurationDialog . modal ( "hide" ) ;
self . _copyConfig ( ) ;
2017-03-31 14:52:48 +00:00
self . requestData ( { refresh _repo : true , refresh _notices : true , eval _notices : true } ) ;
2015-09-22 09:36:57 +00:00
} ) ;
} ;
self . _copyConfig = function ( ) {
self . config _repositoryUrl ( self . settingsViewModel . settings . plugins . pluginmanager . repository ( ) ) ;
self . config _repositoryTtl ( self . settingsViewModel . settings . plugins . pluginmanager . repository _ttl ( ) ) ;
2017-03-31 14:52:48 +00:00
self . config _noticesUrl ( self . settingsViewModel . settings . plugins . pluginmanager . notices ( ) ) ;
self . config _noticesTtl ( self . settingsViewModel . settings . plugins . pluginmanager . notices _ttl ( ) ) ;
2015-09-28 17:53:30 +00:00
self . config _pipAdditionalArgs ( self . settingsViewModel . settings . plugins . pluginmanager . pip _args ( ) ) ;
2015-09-30 11:36:00 +00:00
self . config _pipForceUser ( self . settingsViewModel . settings . plugins . pluginmanager . pip _force _user ( ) ) ;
2015-09-22 09:36:57 +00:00
} ;
2015-05-29 14:31:43 +00:00
self . installed = function ( data ) {
return _ . includes ( self . installedPlugins ( ) , data . id ) ;
} ;
self . isCompatible = function ( data ) {
return data . is _compatible . octoprint && data . is _compatible . os ;
} ;
self . installButtonText = function ( data ) {
2017-03-31 15:53:49 +00:00
return self . isCompatible ( data ) ? ( self . installed ( data ) ? gettext ( "Reinstall" ) : gettext ( "Install" ) ) : ( data . disabled ? gettext ( "Disabled" ) : gettext ( "Incompatible" ) ) ;
2015-05-29 14:31:43 +00:00
} ;
self . _displayNotification = function ( response , titleSuccess , textSuccess , textRestart , textReload , titleError , textError ) {
2015-10-01 12:20:37 +00:00
var notification ;
var beforeClose = function ( notification ) {
self . notifications = _ . without ( self . notifications , notification ) ;
} ;
2015-05-29 14:31:43 +00:00
if ( response . result ) {
if ( response . needs _restart ) {
2015-10-01 12:20:37 +00:00
var options = {
2015-05-29 14:31:43 +00:00
title : titleSuccess ,
text : textRestart ,
2015-10-01 12:20:37 +00:00
buttons : {
2016-11-21 15:14:09 +00:00
closer : true ,
2015-10-01 12:20:37 +00:00
sticker : false
} ,
callbacks : {
before _close : beforeClose
} ,
2015-05-29 14:31:43 +00:00
hide : false
2015-10-01 12:20:37 +00:00
} ;
2017-05-16 13:54:52 +00:00
var restartClicked = false ;
2015-10-01 12:20:37 +00:00
if ( self . restartCommandSpec ) {
options . confirm = {
confirm : true ,
buttons : [ {
text : gettext ( "Restart now" ) ,
2017-05-16 13:54:52 +00:00
click : function ( notice ) {
if ( restartClicked ) return ;
restartClicked = true ;
2015-10-01 12:20:37 +00:00
showConfirmationDialog ( {
message : gettext ( "This will restart your OctoPrint server." ) ,
onproceed : function ( ) {
2015-10-01 12:57:41 +00:00
OctoPrint . system . executeCommand ( "core" , "restart" )
. done ( function ( ) {
2017-05-16 13:54:52 +00:00
notice . remove ( ) ;
2015-10-01 12:20:37 +00:00
new PNotify ( {
title : gettext ( "Restart in progress" ) ,
text : gettext ( "The server is now being restarted in the background" )
} )
2015-10-01 12:57:41 +00:00
} )
. fail ( function ( ) {
2015-10-01 12:20:37 +00:00
new PNotify ( {
title : gettext ( "Something went wrong" ) ,
text : gettext ( "Trying to restart the server produced an error, please check octoprint.log for details. You'll have to restart manually." )
} )
2015-10-01 12:57:41 +00:00
} ) ;
2017-05-16 13:54:52 +00:00
} ,
onclose : function ( ) {
restartClicked = false ;
2015-10-01 12:20:37 +00:00
}
} ) ;
}
} ]
}
}
notification = PNotify . singleButtonNotify ( options ) ;
2015-05-29 14:31:43 +00:00
} else if ( response . needs _refresh ) {
2017-05-16 13:54:52 +00:00
var refreshClicked = false ;
2015-10-01 12:20:37 +00:00
notification = PNotify . singleButtonNotify ( {
2015-05-29 14:31:43 +00:00
title : titleSuccess ,
text : textReload ,
confirm : {
confirm : true ,
buttons : [ {
text : gettext ( "Reload now" ) ,
click : function ( ) {
2017-05-16 13:54:52 +00:00
if ( refreshClicked ) return ;
refreshClicked = true ;
2015-05-29 14:31:43 +00:00
location . reload ( true ) ;
}
} ]
} ,
buttons : {
2016-11-21 15:14:09 +00:00
closer : true ,
2015-05-29 14:31:43 +00:00
sticker : false
} ,
2015-10-01 12:20:37 +00:00
callbacks : {
before _close : beforeClose
} ,
2015-05-29 14:31:43 +00:00
hide : false
} )
} else {
2015-10-01 12:20:37 +00:00
notification = new PNotify ( {
2015-05-29 14:31:43 +00:00
title : titleSuccess ,
text : textSuccess ,
type : "success" ,
2015-10-01 12:20:37 +00:00
callbacks : {
before _close : beforeClose
} ,
2015-05-29 14:31:43 +00:00
hide : false
} )
}
} else {
2015-10-01 12:20:37 +00:00
notification = new PNotify ( {
2015-05-29 14:31:43 +00:00
title : titleError ,
text : textError ,
type : "error" ,
2015-10-01 12:20:37 +00:00
callbacks : {
before _close : beforeClose
} ,
2015-05-29 14:31:43 +00:00
hide : false
} ) ;
}
2015-10-01 12:20:37 +00:00
self . notifications . push ( notification ) ;
2015-05-29 14:31:43 +00:00
} ;
self . _markWorking = function ( title , line ) {
self . working ( true ) ;
self . workingTitle ( title ) ;
self . loglines . removeAll ( ) ;
self . loglines . push ( { line : line , stream : "message" } ) ;
2016-11-23 13:28:50 +00:00
self . _scrollWorkingOutputToEnd ( ) ;
2015-05-29 14:31:43 +00:00
2016-11-23 14:11:35 +00:00
self . workingDialog . modal ( { keyboard : false , backdrop : "static" , show : true } ) ;
2015-05-29 14:31:43 +00:00
} ;
2017-04-04 13:18:37 +00:00
self . _markDone = function ( error ) {
2015-05-29 14:31:43 +00:00
self . working ( false ) ;
2017-04-04 13:18:37 +00:00
if ( error ) {
self . loglines . push ( { line : gettext ( "Error!" ) , stream : "error" } ) ;
self . loglines . push ( { line : error , stream : "error" } )
} else {
self . loglines . push ( { line : gettext ( "Done!" ) , stream : "message" } ) ;
}
2015-05-29 14:31:43 +00:00
self . _scrollWorkingOutputToEnd ( ) ;
} ;
self . _scrollWorkingOutputToEnd = function ( ) {
2017-05-10 07:25:53 +00:00
self . workingOutput . scrollTop ( self . workingOutput [ 0 ] . scrollHeight - self . workingOutput . height ( ) ) ;
2015-05-29 14:31:43 +00:00
} ;
self . _getToggleCommand = function ( data ) {
2016-11-18 12:01:14 +00:00
var disable = ( data . enabled || data . pending _enable || ( data . safe _mode _victim && data . safe _mode _enabled ) ) && ! data . pending _disable ;
return disable ? "disable" : "enable" ;
2015-05-29 14:31:43 +00:00
} ;
self . toggleButtonCss = function ( data ) {
var icon = self . _getToggleCommand ( data ) == "enable" ? "icon-circle-blank" : "icon-circle" ;
2015-06-18 09:37:08 +00:00
var disabled = ( self . enableToggle ( data ) ) ? "" : " disabled" ;
2015-05-29 14:31:43 +00:00
return icon + disabled ;
} ;
self . toggleButtonTitle = function ( data ) {
2016-11-18 12:01:14 +00:00
var command = self . _getToggleCommand ( data ) ;
if ( command == "enable" ) {
if ( data . safe _mode _victim && ! data . safe _mode _enabled ) {
return gettext ( "Disabled due to active safe mode" ) ;
} else {
return gettext ( "Enable Plugin" ) ;
}
} else {
return gettext ( "Disable Plugin" ) ;
}
2015-05-29 14:31:43 +00:00
} ;
2017-03-31 14:52:48 +00:00
self . showPluginNotifications = function ( plugin ) {
if ( ! plugin . notifications || plugin . notifications . length == 0 ) return ;
self . _removeAllNoticeNotificationsForPlugin ( plugin . key ) ;
_ . each ( plugin . notifications , function ( notification ) {
self . _showPluginNotification ( plugin , notification ) ;
} ) ;
} ;
self . showPluginNotificationsLinkText = function ( plugins ) {
if ( ! plugins . notifications || plugins . notifications . length == 0 ) return ;
var count = plugins . notifications . length ;
var importantCount = _ . filter ( plugins . notifications , function ( notification ) { return notification . important } ) . length ;
if ( count > 1 ) {
if ( importantCount ) {
return _ . sprintf ( gettext ( "There are %(count)d notices (%(important)d marked as important) available regarding this plugin - click to show!" ) , { count : count , important : importantCount } ) ;
} else {
return _ . sprintf ( gettext ( "There are %(count)d notices available regarding this plugin - click to show!" ) , { count : count } ) ;
}
} else {
if ( importantCount ) {
return gettext ( "There is an important notice available regarding this plugin - click to show!" ) ;
} else {
return gettext ( "There is a notice available regarding this plugin - click to show!" ) ;
}
}
} ;
self . _showPluginNotification = function ( plugin , notification ) {
var name = plugin . name ;
var version = plugin . version ;
var important = notification . important ;
var link = notification . link ;
var title ;
if ( important ) {
title = _ . sprintf ( gettext ( "Important notice regarding plugin \"%(name)s\"" ) , { name : name } ) ;
} else {
title = _ . sprintf ( gettext ( "Notice regarding plugin \"%(name)s\"" ) , { name : name } ) ;
}
var text = "" ;
if ( notification . versions && notification . versions . length > 0 ) {
var versions = _ . map ( notification . versions , function ( v ) { return ( v == version ) ? "<strong>" + v + "</strong>" : v ; } ) . join ( ", " ) ;
text += "<small>" + _ . sprintf ( gettext ( "Affected versions: %(versions)s" ) , { versions : versions } ) + "</small>" ;
} else {
text += "<small>" + gettext ( "Affected versions: all" ) + "</small>" ;
}
text += "<p>" + notification . text + "</p>" ;
if ( link ) {
text += "<p><a href='" + link + "' target='_blank'>" + gettext ( "Read more..." ) + "</a></p>" ;
}
var beforeClose = function ( notification ) {
if ( ! self . noticeNotifications [ plugin . key ] ) return ;
self . noticeNotifications [ plugin . key ] = _ . without ( self . noticeNotifications [ plugin . key ] , notification ) ;
} ;
var options = {
title : title ,
text : text ,
type : ( important ) ? "error" : "notice" ,
before _close : beforeClose ,
hide : false ,
confirm : {
confirm : true ,
buttons : [ {
text : gettext ( "Later" ) ,
click : function ( notice ) {
self . _hideNoticeNotification ( plugin . key , notification . date ) ;
notice . remove ( ) ;
notice . get ( ) . trigger ( "pnotify.cancel" , notice ) ;
}
} , {
text : gettext ( "Mark read" ) ,
click : function ( notice ) {
self . _ignoreNoticeNotification ( plugin . key , notification . date ) ;
notice . remove ( ) ;
notice . get ( ) . trigger ( "pnotify.cancel" , notice ) ;
}
} ]
} ,
buttons : {
sticker : false ,
closer : false
}
} ;
if ( ! self . noticeNotifications [ plugin . key ] ) {
self . noticeNotifications [ plugin . key ] = [ ] ;
}
self . noticeNotifications [ plugin . key ] . push ( new PNotify ( options ) ) ;
} ;
self . _removeAllNoticeNotifications = function ( ) {
_ . each ( _ . keys ( self . noticeNotifications ) , function ( key ) {
self . _removeAllNoticeNotificationsForPlugin ( key ) ;
} ) ;
} ;
self . _removeAllNoticeNotificationsForPlugin = function ( key ) {
if ( ! self . noticeNotifications [ key ] || ! self . noticeNotifications [ key ] . length ) return ;
_ . each ( self . noticeNotifications [ key ] , function ( notification ) {
notification . remove ( ) ;
} ) ;
} ;
self . _hideNoticeNotification = function ( key , date ) {
if ( ! self . hiddenNoticeNotifications [ key ] ) {
self . hiddenNoticeNotifications [ key ] = [ ] ;
}
if ( ! _ . contains ( self . hiddenNoticeNotifications [ key ] , date ) ) {
self . hiddenNoticeNotifications [ key ] . push ( date ) ;
}
} ;
self . _isNoticeNotificationHidden = function ( key , date ) {
if ( ! self . hiddenNoticeNotifications [ key ] ) return false ;
return _ . any ( _ . map ( self . hiddenNoticeNotifications [ key ] , function ( d ) { return date == d ; } ) ) ;
} ;
var noticeLocalStorageKey = "plugin.pluginmanager.seen_notices" ;
self . _ignoreNoticeNotification = function ( key , date ) {
if ( ! Modernizr . localstorage )
return false ;
if ( ! self . loginState . isAdmin ( ) )
return false ;
var currentString = localStorage [ noticeLocalStorageKey ] ;
var current ;
if ( currentString === undefined ) {
current = { } ;
} else {
current = JSON . parse ( currentString ) ;
}
if ( ! current [ self . loginState . username ( ) ] ) {
current [ self . loginState . username ( ) ] = { } ;
}
if ( ! current [ self . loginState . username ( ) ] [ key ] ) {
current [ self . loginState . username ( ) ] [ key ] = [ ] ;
}
if ( ! _ . contains ( current [ self . loginState . username ( ) ] [ key ] , date ) ) {
current [ self . loginState . username ( ) ] [ key ] . push ( date ) ;
localStorage [ noticeLocalStorageKey ] = JSON . stringify ( current ) ;
}
} ;
self . _isNoticeNotificationIgnored = function ( key , date ) {
if ( ! Modernizr . localstorage )
return false ;
if ( localStorage [ noticeLocalStorageKey ] == undefined )
return false ;
var knownData = JSON . parse ( localStorage [ noticeLocalStorageKey ] ) ;
if ( ! self . loginState . isAdmin ( ) )
return true ;
var userData = knownData [ self . loginState . username ( ) ] ;
if ( userData === undefined )
return false ;
return userData [ key ] && _ . contains ( userData [ key ] , date ) ;
} ;
2015-05-29 14:31:43 +00:00
self . onBeforeBinding = function ( ) {
self . settings = self . settingsViewModel . settings ;
} ;
self . onUserLoggedIn = function ( user ) {
if ( user . admin ) {
2017-03-31 14:52:48 +00:00
self . requestData ( { eval _notices : true } ) ;
2015-10-01 12:20:37 +00:00
} else {
self . onUserLoggedOut ( ) ;
}
} ;
self . onUserLoggedOut = function ( ) {
2016-11-21 15:14:09 +00:00
self . _closeAllNotifications ( ) ;
} ;
self . _closeAllNotifications = function ( ) {
2015-10-01 12:20:37 +00:00
if ( self . notifications ) {
_ . each ( self . notifications , function ( notification ) {
notification . remove ( ) ;
} ) ;
2015-05-29 14:31:43 +00:00
}
} ;
2016-11-21 15:14:09 +00:00
self . onServerDisconnect = function ( ) {
self . _closeAllNotifications ( ) ;
return true ;
} ;
2015-05-29 14:31:43 +00:00
self . onStartup = function ( ) {
self . workingDialog = $ ( "#settings_plugin_pluginmanager_workingdialog" ) ;
self . workingOutput = $ ( "#settings_plugin_pluginmanager_workingdialog_output" ) ;
self . repositoryDialog = $ ( "#settings_plugin_pluginmanager_repositorydialog" ) ;
$ ( "#settings_plugin_pluginmanager_repositorydialog_list" ) . slimScroll ( {
height : "306px" ,
size : "5px" ,
distance : "0" ,
railVisible : true ,
alwaysVisible : true ,
scrollBy : "102px"
} ) ;
} ;
self . onDataUpdaterPluginMessage = function ( plugin , data ) {
if ( plugin != "pluginmanager" ) {
return ;
}
if ( ! self . loginState . isAdmin ( ) ) {
return ;
}
if ( ! data . hasOwnProperty ( "type" ) ) {
return ;
}
var messageType = data . type ;
if ( messageType == "loglines" && self . working ( ) ) {
_ . each ( data . loglines , function ( line ) {
2016-11-23 13:28:50 +00:00
self . loglines . push ( self . _preprocessLine ( line ) ) ;
2015-05-29 14:31:43 +00:00
} ) ;
self . _scrollWorkingOutputToEnd ( ) ;
} else if ( messageType == "result" ) {
var titleSuccess , textSuccess , textRestart , textReload , titleError , textError ;
var action = data . action ;
var name = "Unknown" ;
if ( action == "install" ) {
2015-06-19 22:56:26 +00:00
var unknown = false ;
2015-05-29 14:31:43 +00:00
if ( data . hasOwnProperty ( "plugin" ) ) {
2015-06-19 22:56:26 +00:00
if ( data . plugin == "unknown" ) {
unknown = true ;
} else {
name = data . plugin . name ;
}
2015-05-29 14:31:43 +00:00
}
2015-06-19 22:56:26 +00:00
if ( unknown ) {
titleSuccess = _ . sprintf ( gettext ( "Plugin installed" ) ) ;
textSuccess = gettext ( "A plugin was installed successfully, however it was impossible to detect which one. Please Restart OctoPrint to make sure everything will be registered properly" ) ;
textRestart = textSuccess ;
textReload = textSuccess ;
} else if ( data . was _reinstalled ) {
2015-05-29 14:31:43 +00:00
titleSuccess = _ . sprintf ( gettext ( "Plugin \"%(name)s\" reinstalled" ) , { name : name } ) ;
textSuccess = gettext ( "The plugin was reinstalled successfully" ) ;
textRestart = gettext ( "The plugin was reinstalled successfully, however a restart of OctoPrint is needed for that to take effect." ) ;
textReload = gettext ( "The plugin was reinstalled successfully, however a reload of the page is needed for that to take effect." ) ;
} else {
titleSuccess = _ . sprintf ( gettext ( "Plugin \"%(name)s\" installed" ) , { name : name } ) ;
textSuccess = gettext ( "The plugin was installed successfully" ) ;
textRestart = gettext ( "The plugin was installed successfully, however a restart of OctoPrint is needed for that to take effect." ) ;
textReload = gettext ( "The plugin was installed successfully, however a reload of the page is needed for that to take effect." ) ;
}
titleError = gettext ( "Something went wrong" ) ;
2017-04-04 13:18:37 +00:00
var source = "unknown" ;
if ( data . hasOwnProperty ( "source" ) ) {
source = data . source ;
}
var sourceType = "unknown" ;
if ( data . hasOwnProperty ( "source_type" ) ) {
sourceType = data . source _type ;
2015-05-29 14:31:43 +00:00
}
if ( data . hasOwnProperty ( "reason" ) ) {
if ( data . was _reinstalled ) {
2017-04-04 13:18:37 +00:00
if ( sourceType == "path" ) {
textError = _ . sprintf ( gettext ( "Reinstalling the plugin from file failed: %(reason)s" ) , { reason : data . reason } ) ;
} else {
textError = _ . sprintf ( gettext ( "Reinstalling the plugin from \"%(source)s\" failed: %(reason)s" ) , { reason : data . reason , source : source } ) ;
}
2015-05-29 14:31:43 +00:00
} else {
2017-04-04 13:18:37 +00:00
if ( sourceType == "path" ) {
textError = _ . sprintf ( gettext ( "Installing the plugin from file failed: %(reason)s" ) , { reason : data . reason } ) ;
} else {
textError = _ . sprintf ( gettext ( "Installing the plugin from \"%(source)s\" failed: %(reason)s" ) , { reason : data . reason , source : source } ) ;
}
2015-05-29 14:31:43 +00:00
}
} else {
if ( data . was _reinstalled ) {
2017-04-04 13:18:37 +00:00
if ( sourceType == "path" ) {
textError = gettext ( "Reinstalling the plugin from file failed, please see the log for details." ) ;
} else {
textError = _ . sprintf ( gettext ( "Reinstalling the plugin from \"%(source)s\" failed, please see the log for details." ) , { source : source } ) ;
}
2015-05-29 14:31:43 +00:00
} else {
2017-04-04 13:18:37 +00:00
if ( sourceType == "path" ) {
textError = gettext ( "Installing the plugin from file failed, please see the log for details." ) ;
} else {
textError = _ . sprintf ( gettext ( "Installing the plugin from \"%(source)s\" failed, please see the log for details." ) , { source : source } ) ;
}
2015-05-29 14:31:43 +00:00
}
}
} else if ( action == "uninstall" ) {
if ( data . hasOwnProperty ( "plugin" ) ) {
name = data . plugin . name ;
}
titleSuccess = _ . sprintf ( gettext ( "Plugin \"%(name)s\" uninstalled" ) , { name : name } ) ;
textSuccess = gettext ( "The plugin was uninstalled successfully" ) ;
textRestart = gettext ( "The plugin was uninstalled successfully, however a restart of OctoPrint is needed for that to take effect." ) ;
textReload = gettext ( "The plugin was uninstalled successfully, however a reload of the page is needed for that to take effect." ) ;
titleError = gettext ( "Something went wrong" ) ;
if ( data . hasOwnProperty ( "reason" ) ) {
textError = _ . sprintf ( gettext ( "Uninstalling the plugin failed: %(reason)s" ) , { reason : data . reason } ) ;
} else {
textError = gettext ( "Uninstalling the plugin failed, please see the log for details." ) ;
}
} else if ( action == "enable" ) {
if ( data . hasOwnProperty ( "plugin" ) ) {
name = data . plugin . name ;
}
titleSuccess = _ . sprintf ( gettext ( "Plugin \"%(name)s\" enabled" ) , { name : name } ) ;
textSuccess = gettext ( "The plugin was enabled successfully." ) ;
textRestart = gettext ( "The plugin was enabled successfully, however a restart of OctoPrint is needed for that to take effect." ) ;
textReload = gettext ( "The plugin was enabled successfully, however a reload of the page is needed for that to take effect." ) ;
titleError = gettext ( "Something went wrong" ) ;
if ( data . hasOwnProperty ( "reason" ) ) {
textError = _ . sprintf ( gettext ( "Toggling the plugin failed: %(reason)s" ) , { reason : data . reason } ) ;
} else {
textError = gettext ( "Toggling the plugin failed, please see the log for details." ) ;
}
} else if ( action == "disable" ) {
if ( data . hasOwnProperty ( "plugin" ) ) {
name = data . plugin . name ;
}
titleSuccess = _ . sprintf ( gettext ( "Plugin \"%(name)s\" disabled" ) , { name : name } ) ;
textSuccess = gettext ( "The plugin was disabled successfully." ) ;
textRestart = gettext ( "The plugin was disabled successfully, however a restart of OctoPrint is needed for that to take effect." ) ;
textReload = gettext ( "The plugin was disabled successfully, however a reload of the page is needed for that to take effect." ) ;
titleError = gettext ( "Something went wrong" ) ;
if ( data . hasOwnProperty ( "reason" ) ) {
textError = _ . sprintf ( gettext ( "Toggling the plugin failed: %(reason)s" ) , { reason : data . reason } ) ;
} else {
textError = gettext ( "Toggling the plugin failed, please see the log for details." ) ;
}
} else {
return ;
}
self . _displayNotification ( data , titleSuccess , textSuccess , textRestart , textReload , titleError , textError ) ;
self . requestData ( ) ;
}
} ;
2016-11-23 13:28:50 +00:00
self . _forcedStdoutLine = /You are using pip version .*?, however version .*? is available\.|You should consider upgrading via the '.*?' command\./ ;
self . _preprocessLine = function ( line ) {
if ( line . stream == "stderr" && line . line . match ( self . _forcedStdoutLine ) ) {
line . stream = "stdout" ;
}
return line ;
}
2015-05-29 14:31:43 +00:00
}
// view model class, parameters for constructor, container to bind to
2015-10-01 12:20:37 +00:00
ADDITIONAL _VIEWMODELS . push ( [
PluginManagerViewModel ,
[ "loginStateViewModel" , "settingsViewModel" , "printerStateViewModel" , "systemViewModel" ] ,
"#settings_plugin_pluginmanager"
] ) ;
2015-05-29 14:31:43 +00:00
} ) ;