2015-08-10 22:46:01 +02:00
var repoindex = ( function ( repoindex ) {
var RepoEntry = { } ;
RepoEntry . prototype = new repoindex . Entry ( ) ;
RepoEntry . prototype . constructor = RepoEntry ;
RepoEntry = function ( repoInfo , enabled ) {
repoindex . Entry . prototype . constructor . call ( this , repoInfo , enabled ) ;
this . info . currentServer = 0 ;
this . rowElement . onclick = function ( ) {
repoindex . pageManager . repoManager . showRepoInfoForIndex ( this . entry . info . index ) ;
} ;
this . initTableRow = function ( ) {
this . rowElement . addCell ( this . info . name ) ;
this . rowElement . addCell ( this . info . desc ) ;
//this.rowElement.addCell(this.info.servers && this.info.currentServer < this.info.servers.length ? this.info.servers[this.info.currentServer] : "none");
} ;
this . initTableRow ( ) ;
// create link
this . createLink = function ( ) {
this . link = document . createElement ( "a" ) ;
this . link . href = "#" ;
this . link . className = enabled ? "btn btn-primary" : "btn btn-default" ;
this . link . setAttribute ( "role" , "button" ) ;
this . link . repo = this ;
this . link . onclick = function ( ) {
if ( repoindex . pageManager . repoManager . buttonContainerExclusiveButton . checked ) {
repoindex . pageManager . repoManager . updateEnabledAll ( false ) ;
}
this . repo . toggleEnabled ( ) ;
return false ;
} ;
this . link . appendChild ( document . createTextNode ( repoInfo . name ) ) ;
this . link . title = repoInfo . desc ;
// use Bootstrap tooltip
this . link . setAttribute ( "data-placement" , "bottom" ) ;
$ ( this . link ) . tooltip ( ) ;
// create badge with package count
var span = document . createElement ( "span" ) ;
span . className = "badge" ;
span . appendChild ( document . createTextNode ( repoInfo . packages . length ) ) ;
this . link . appendChild ( document . createTextNode ( " " ) ) ;
this . link . appendChild ( span ) ;
this . link . add = function ( ) {
repoindex . pageManager . repoManager . buttonContainer . appendChild ( this ) ;
} ;
this . link . remove = function ( ) {
this . parent . removeChild ( this ) ;
} ;
} ;
this . createLink ( ) ;
this . link . add ( ) ;
// provide a function to toggle enabled/disabled
this . updateEnabled = function ( enabled ) {
if ( this . enabled !== enabled ) {
this . link . className = ( this . enabled = enabled ) ? "btn btn-primary" : "btn btn-default" ;
this . statusChanged ( this ) ;
}
} ;
this . toggleEnabled = function ( ) {
this . updateEnabled ( ! this . enabled ) ;
} ;
} ;
repoindex . RepoEntryManager = { } ;
repoindex . RepoEntryManager . prototype = new repoindex . EntryManager ( ) ;
repoindex . RepoEntryManager . prototype . constructor = repoindex . RepoEntryManager ;
repoindex . RepoEntryManager = function ( pagination ) {
repoindex . EntryManager . prototype . constructor . call ( this , RepoEntry , document . getElementById ( "repos" ) , pagination ) ;
this . entryName = "repository" ;
this . entryNamePlural = "repositories" ;
this . buttonRow = document . getElementById ( "row_repos_buttons" ) ;
this . buttonContainer = document . getElementById ( "repos_buttons" ) ;
this . buttonContainerOptionsDropdown = document . getElementById ( "repos_buttons_options_dropdown" ) ;
this . buttonContainerExclusiveButton = document . getElementById ( "repos_buttons_exclusive" ) ;
this . applyRepoStatusChange = function ( ) {
// this is the RepoEntry object in this function!
var pageMgr = repoindex . pageManager ;
var repoEntries = pageMgr . repoManager . entries ;
var repoFilter = [ ] ;
for ( var i = 0 , end = repoEntries . length ; i < end ; ++ i ) {
if ( repoEntries [ i ] . enabled ) {
repoFilter . push ( repoEntries [ i ] . info . name ) ;
}
}
pageMgr . packageManager . filterRepos = pageMgr . groupManager . filterRepos = repoFilter ;
pageMgr . packageManager . invalidate ( ) ;
pageMgr . groupManager . invalidate ( ) ;
} ;
// provide a function to add repo entries
this . addEntry = function ( repoInfo ) {
var entry = new RepoEntry ( repoInfo , true ) ;
entry . statusChanged = this . applyRepoStatusChange ;
entry . pageManager = this ;
entry . repoEntryManager = this ;
entry . info . index = this . entries . length ;
this . entries . push ( entry ) ;
} ;
this . baseRemoveEntries = this . removeEntries ;
this . removeEntries = function ( ) {
for ( var i = 0 ; i < this . entries . length ; ++ i ) {
this . entries [ i ] . link . remove ( ) ;
}
this . baseRemoveEntries ( ) ;
} ;
this . updateEnabledAll = function ( enabled ) {
for ( var i = 0 ; i < this . entries . length ; ++ i ) {
this . entries [ i ] . updateEnabled ( enabled ) ;
}
} ;
// handle a page selection
this . pagination . pageSelected = function ( pageElement ) {
var mgr = this . entryManager ;
// remove elements from previously selected page
mgr . entryContainer . wipeChildren ( ) ;
// if there is no page because there are no package entries, pageElement is null
if ( pageElement ) {
// show elements of selected page
pageElement . forRange ( function ( i ) {
var entry = mgr . filteredEntries [ i ] ;
entry . add ( mgr . entryContainer ) ;
} , mgr . filteredEntries . length ) ;
}
} ;
this . infoBox = document . getElementById ( "repos_info" ) ;
this . showRepoInfo = function ( repo ) {
var determineEntry = function ( ) {
var res = repoindex . pageManager . repoManager . entries . filter ( function ( entry ) {
return entry . info . name === repo ;
} ) ;
// entry exists?
if ( res . length > 0 ) {
// yes -> full package info available?
repoindex . pageManager . repoManager . showRepoInfoForIndex ( res [ 0 ] . info . index ) ;
} else {
// no -> show error
repoindex . pageManager . repoManager . showRepoNotFound ( repo ) ;
}
} ;
// basic repo info available?
if ( repoindex . alpmClient . hasBasicRepoInfo ) {
// yes -> can determine entry instantly
determineEntry ( ) ;
} else {
// no -> request info, use callback to determine entry when info becomes available
repoindex . alpmClient . requestBasicRepoInfo ( determineEntry ) ;
}
} ;
this . showRepoInfoForIndex = function ( entryIndex ) {
var entry = this . entryByIndex ( entryIndex ) ;
if ( entry ) {
var i = entry . info ;
repoindex . setText ( "repo_name" , i . name ) ;
repoindex . setText ( "repo_desc" , i . desc ) ;
repoindex . setText ( "repo_pkgcount" , i . packages . length ) ;
repoindex . setText ( "repo_usage" , repoindex . makeArray ( i . usage , ", " ) ) ;
repoindex . setText ( "repo_siglevel" , repoindex . makeArray ( i . sigLevel , ", " ) ) ;
2015-08-19 02:13:28 +02:00
repoindex . setText ( "repo_upgrade_sources" , repoindex . makeArray ( i . upgradeSources , ", " ) ) ;
2015-08-10 22:46:01 +02:00
var invokeUpdateLookupParams = { repo : i . name , invoke : "updatelookup" } ;
repoindex . setDownloadButton ( "repo_checkforupdates" , "check for updates" , repoindex . makeHash ( repoindex . Pages . Repositories , invokeUpdateLookupParams , true ) , function ( ) {
repoindex . pageManager . repoManager . showAvailableUpdates ( i . name ) ;
repoindex . pageManager . denoteHash ( repoindex . Pages . Repositories , invokeUpdateLookupParams ) ;
} , "refresh" ) ;
// set currentInfo (the pageManager needs this value to update the hash)
this . currentInfo = i ;
// ensures, that the "Package Info" box (with the properties just set) is shown
repoindex . pageManager . showRepoInfo ( ) ;
}
} ;
this . showRepoNotFound = function ( repo ) {
repoindex . pageManager . msgboxCritical (
"Repository not found" ,
"The repository <i>" + repoindex . escapeHtml ( repo ) + "</i> can not be found." ,
true ) ;
} ;
this . showAvailableUpdates = function ( repo ) {
var requestUpdates = function ( ) {
var showUpdates = function ( availableUpdates ) {
// check for errors
if ( Array . isArray ( availableUpdates . errors ) ) {
for ( var i = 0 ; i < availableUpdates . errors . length ; ++ i ) {
repoindex . pageManager . addError ( "Error: " + availableUpdates . errors [ i ] ) ;
}
} else {
// create package entries for the updates
var updateEntries = [ ] ;
var updates = [
{
name : "software upgrade" ,
namePlural : "software upgrades" ,
style : "background-color: " + repoindex . softwareUpgradeBackgroundColor ,
color : repoindex . softwareUpgradeBackgroundColor ,
entries : Array . isArray ( availableUpdates . softwareUpdates ) ? availableUpdates . softwareUpdates : [ ] ,
count : Array . isArray ( availableUpdates . softwareUpdates ) ? availableUpdates . softwareUpdates . length : 0
} , {
name : "package-only upgrade" ,
namePlural : "package-only upgrades" ,
style : "background-color: " + repoindex . packageUpgradeBackgroundColor ,
color : repoindex . packageUpgradeBackgroundColor ,
entries : Array . isArray ( availableUpdates . packageOnlyUpdates ) ? availableUpdates . packageOnlyUpdates : [ ] ,
count : Array . isArray ( availableUpdates . packageOnlyUpdates ) ? availableUpdates . packageOnlyUpdates . length : 0
} , {
name : "downgrade" ,
namePlural : "downgrades" ,
style : "background-color: " + repoindex . downgradesBackgroundColor ,
color : repoindex . downgradesBackgroundColor ,
entries : Array . isArray ( availableUpdates . downgrades ) ? availableUpdates . downgrades : [ ] ,
count : Array . isArray ( availableUpdates . downgrades ) ? availableUpdates . downgrades . length : 0
} , {
name : "orphaned package" ,
namePlural : "orphaned packages" ,
style : "background-color: " + repoindex . orphanedPackageBackgroundColor ,
color : repoindex . orphanedPackageBackgroundColor ,
entries : Array . isArray ( availableUpdates . orphanedPackages ) ? availableUpdates . orphanedPackages : [ ] ,
count : Array . isArray ( availableUpdates . orphanedPackages ) ? availableUpdates . orphanedPackages . length : 0
}
] ;
var pkgMgr = repoindex . pageManager . packageManager ;
for ( var i1 = 0 ; i1 < updates . length ; ++ i1 ) {
for ( var i2 = 0 ; i2 < updates [ i1 ] . entries . length ; ++ i2 ) {
var newEntry = pkgMgr . createCustomEntry ( updates [ i1 ] . color ) ;
newEntry . info . index = updateEntries . length ;
2015-08-19 02:13:28 +02:00
if ( updates [ i1 ] . entries [ i2 ] . pkg ) {
newEntry . applyBasicInfo ( updates [ i1 ] . entries [ i2 ] . pkg , true ) ;
if ( updates [ i1 ] . entries [ i2 ] . prevVersion ) {
newEntry . info . ver = updates [ i1 ] . entries [ i2 ] . prevVersion + " → " + ( newEntry . info . ver ? newEntry . info . ver : "?" ) ;
}
newEntry . updateTableRow ( ) ;
} else {
newEntry . applyBasicInfo ( updates [ i1 ] . entries [ i2 ] ) ;
}
2015-08-10 22:46:01 +02:00
updateEntries . push ( newEntry ) ;
}
}
if ( Array . isArray ( availableUpdates . warnings ) ) {
for ( var i = 0 ; i < availableUpdates . warnings . length ; ++ i ) {
repoindex . pageManager . addError ( "Warning: " + availableUpdates . warnings [ i ] ) ;
}
}
// show updates via package manager
2015-08-19 02:13:28 +02:00
pkgMgr . filterName = undefined ;
2015-08-10 22:46:01 +02:00
pkgMgr . customSelection = updateEntries ;
pkgMgr . customSelectionName = "upgrade" ;
pkgMgr . customSelectionNamePlural = "upgrades" ;
var quandityInfo = repoindex . makeQuandityInfo ( updates ) ;
if ( quandityInfo ) {
2015-08-19 02:13:28 +02:00
pkgMgr . customSelectionInfoText = "Updates for the repository <i>"
+ repoindex . escapeHtml ( repo )
+ "</i>: " + quandityInfo
+ repoindex . removeFilterButtonHtml ;
2015-08-10 22:46:01 +02:00
}
pkgMgr . filterDescr = "for the repository"
pkgMgr . invalidate ( ) ;
repoindex . pageManager . setPage ( repoindex . Pages . Packages ) ;
}
} ;
// determine sync databases (this is done by the server now)
//var syncDbNames = [];
//var repoEntries = repoindex.pageManager.repoManager.entries;
//for(var index = 0; index < repoEntries.length; ++index) {
// if(repoEntries[index].info.name !== repo) {
// syncDbNames.push(repoEntries[index].info.name);
// }
//}
repoindex . alpmClient . checkForUpdates ( repo , null , showUpdates ) ;
} ;
// basic repo info available?
if ( repoindex . alpmClient . hasBasicRepoInfo ) {
// yes -> request updates instantly
requestUpdates ( ) ;
} else {
// no -> request info, use callback to go on requesting updates when repo info becomes available
repoindex . alpmClient . requestBasicRepoInfo ( requestUpdates ) ;
}
} ;
} ;
return repoindex ;
} ) ( repoindex || { } ) ;