Changeset 2242 for lliurex-mirror


Ignore:
Timestamp:
Jul 22, 2016, 9:41:16 AM (3 years ago)
Author:
kbut
Message:

wip

Location:
lliurex-mirror/trunk/fuentes/admin-center-lliurex-mirror.install/lliurex-mirror/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lliurex-mirror/trunk/fuentes/admin-center-lliurex-mirror.install/lliurex-mirror/src/js/lliurex-mirror.js

    r2138 r2242  
    11function LliurexMirror(){
    2   this.distros = ['llx16'];
    3   this.defaultdistro = 0;
     2  this.distros = {'llx16':{}};
     3  this.activedistro = 'llx16';
    44  this.progresscolors = {'new':'#4caf50' ,'ok' : '#4caf50' , 'error' : 'red', 'working':'yellow','default':'black'};
    55  this.bars = {};
     
    77  this.progressoptionsdefault = {color:this.progresscolors['ok'], trailcolor:'#9f9f9f', trailWidth:3, strokeWidth: 3, easing: 'easeInOut', text: {value:''}};
    88  this.intervalupdate = null;
     9  this.progress = 0;
     10  this.credentials = [sessionStorage.username , sessionStorage.password];
     11  this.n4dclass = "MirrorManager";
     12}
     13
     14LliurexMirror.prototype.loadMirrorInfo = function loadMirrorInfo(info){
     15  var self = this;
     16  var availabledistros = Object.keys(this.distros);
     17  availabledistros.forEach(function load(distro){
     18    $.extend(self.distros[distro],self.distros[distro],info[distro]);
     19  });
     20}
     21
     22LliurexMirror.prototype.loadProgressBar = function loadProgressBar(container,distro) {
     23  var self = this;
     24  var progressoptions = self.progressoptionsdefault;
     25  var status_mirror = self.distros[distro]['status_mirror'].toLowerCase();
     26  progressoptions['color'] = self.progresscolors.hasOwnProperty(status_mirror) ? self.progresscolors[status_mirror] : self.progresscolors['default']; 
     27  progressoptions['text']['value'] = distro;
     28  self.bars[distro] = new ProgressBar.Circle(container, progressoptions);
     29  self.bars[distro].animate(1 - (100 - self.distros[distro]['progress']) / 100 );
     30}
     31
     32LliurexMirror.prototype.loadOrigin = function loadOrigin(distro){
     33  var self = this;
     34  Utils.n4d(self.credentials, self.n4dclass, "get_mirror_orig", [distro], function getmirrororig(response){
     35    if(response != null && response['status'] == true)
     36      self.distros[distro]['orig'] = response['msg'];
     37      self.showOrig(response['msg']);
     38  });
     39}
     40
     41LliurexMirror.prototype.showOrig = function showOrig(text){
     42  $("#llxmirrororig").text(text);
    943}
    1044
    1145LliurexMirror.prototype.bindEvents = function bindEvents(){
    1246  var self = this;
    13   var distro = self.distros[self.defaultdistro];
     47  var distro = self.activedistro;
    1448  $(document).on("moduleLoaded",function(e,args){
    1549    Utils.n4d('', 'VariablesManager', 'get_variable', ['LLIUREXMIRROR'], function get_variables(response){
    16       self.mirrorinfo = response;
    17       var progressoptions = self.progressoptionsdefault;
    18       var status_mirror = self.mirrorinfo[distro]['status_mirror'].toLowerCase();
    19       progressoptions['color'] = self.progresscolors.hasOwnProperty(status_mirror) ? self.progresscolors[status_mirror] : self.progresscolors['default']; 
    20       progressoptions['text']['value'] = distro;
    21       self.bars[distro] = new ProgressBar.Circle('#llxmirrorprogress', progressoptions);
    22 
    23       self.bars[distro].animate(1 - (100 - self.mirrorinfo[distro]['progress']) / 100 );
    24       self.showOrigin();
     50      self.loadMirrorInfo(response);
     51      self.loadProgressBar('#llxmirrorprogress',distro);
     52      self.loadOrigin(distro);
    2553      self.showArchitecture();
    2654      self.showMirrorSize();
     
    3563  });
    3664
    37   $("#llxmirrorupdate").on('click',function modifyarch(e,args){
    38     self.updateMirror(self);
    39   });
     65  var buttonupdate = document.querySelector("#llxmirrorupdate");
     66  self._updateMirror = self.updateMirror.bind(self);
     67  self._stopUpdate = self.stopUpdate.bind(self);
     68  buttonupdate.addEventListener('click',self._updateMirror,false);
    4069};
    41 
    4270
    4371LliurexMirror.prototype.showOptionsMenu = function showOptionsMenu(self,menuid,buildfunction){
     
    6290  var self = this;
    6391  var buttonGroups = document.createElement('div');
    64   buttonGroups.classList = ["btn-group"];
    65   buttonGroups.classList.add("btn-group-justified");
    66   buttonGroups.classList.add("btn-group-raised");
    6792  var enablei386 = document.createElement('a');
    6893  var enableamd64 = document.createElement('a');
    69   enablei386.classList.add('btn');
    70   enableamd64.classList.add('btn');
    71   enablei386.classList.add('btn-raised');
    72   enableamd64.classList.add('btn-raised');
     94  buttonGroups.classList.add("btn-group","btn-group-justified","btn-group-raised");
     95  enablei386.classList.add('btn','btn-raised');
     96  enableamd64.classList.add('btn','btn-raised');
     97
    7398  if (self.architectures.indexOf('i386')>=0){
    7499    enablei386.classList.add('btn-info');
     
    180205  var n4dclass="MirrorManager";
    181206  var n4dmethod="get_mirror_orig";
    182   var arglist=[self.distros[self.defaultdistro]];
     207  var arglist=[self.activedistro];
    183208  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function getmirrororig(response){
    184209    var value = response['msg'];
     
    221246
    222247LliurexMirror.prototype.showOrigin = function showOrigin(){
    223   var self = this;
    224         var credentials=[sessionStorage.username , sessionStorage.password];
    225         var n4dclass="MirrorManager";
    226         var n4dmethod="get_mirror_orig";
    227         var arglist=[self.distros[self.defaultdistro]];
    228         Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function getmirrororig(response){
    229     if(response != null && response['status'] == true)
    230       $("#llxmirrororig").text(response['msg']);
    231   });
     248
    232249}
    233250
     
    237254        var n4dclass="MirrorManager";
    238255        var n4dmethod="get_mirror_architecture";
    239         var arglist=[self.distros[self.defaultdistro]];
     256        var arglist=[self.activedistro];
    240257        Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function getmirrorarchitecture(response){
    241258    if(response != null && response['status'] == true){
     
    255272  var n4dmethod="get_variable";
    256273  var arglist=['LLIUREXMIRROR'];
    257   var distro = self.distros[self.defaultdistro];
     274  var distro = self.activedistro;
    258275  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function getvariable(response){
    259276    mirrorinfo = response;
    260     if ( ! mirrorinfo.hasOwnProperty(self.distros[self.defaultdistro])){
     277    if ( ! mirrorinfo.hasOwnProperty(self.activedistro)){
    261278      return;
    262279    }
     
    275292  var n4dclass="MirrorManager";
    276293  var n4dmethod="set_mirror_architecture";
    277   var distro = self.distros[self.defaultdistro];
     294  var distro = self.activedistro;
    278295  var arglist=[distro,archs];
    279296  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function(){});
     
    285302  var n4dclass="MirrorManager";
    286303  var n4dmethod="set_mirror_orig";
    287   var distro = self.distros[self.defaultdistro];
     304  var distro = self.activedistro;
    288305  var arglist = [distro,orig];
    289306  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function(){});
    290307}
    291308
    292 LliurexMirror.prototype.updateMirror = function updateMirror(self){
    293 
     309LliurexMirror.prototype.updateMirror = function updateMirror(){
     310  var self = this;
    294311  var credentials=[sessionStorage.username , sessionStorage.password];
    295312  var n4dclass="MirrorManager";
    296313  var n4dmethod="update";
    297   var arglist=[self.distros[self.defaultdistro]];
     314  var arglist=[self.activedistro];
     315 
    298316  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function updatemirror(response){
    299317    if(response['status']){
     
    302320      updatebutton.classList.add('btn-danger');
    303321      updatebutton.innerHTML = 'Cancel';
    304       updatebutton.removeEventListener('click',self.updateMirror);
    305       updatebutton.addEventListener('click',self.stopUpdate);
     322      updatebutton.removeEventListener('click',self._updateMirror);
     323      updatebutton.addEventListener('click',self._stopUpdate,false);
     324      var svg = self.bars[self.activedistro].svg;
     325      svg.classList.add('loader');
    306326      self.intervalupdate = setInterval(function(){
    307327        Utils.n4d(credentials,n4dclass,'is_alive',[],function check_alive(response){
    308328          if (response['status']){
    309             self.bars[self.distros[self.defaultdistro]].path.setAttribute('stroke',self.progresscolors['working']);
     329            self.bars[self.activedistro].path.setAttribute('stroke',self.progresscolors['working']);
    310330            Utils.n4d('', n4dclass, 'get_percentage', arglist, function getpercentage(response){
    311               self.bars[self.distros[self.defaultdistro]].animate(1 - (100 - response['msg']) / 100 );
     331              self.progress = (100 - response['msg']) / 100;
     332              self.bars[self.activedistro].animate(1 - self.progress );
    312333            });
    313334          }
    314335          else{
    315336            if(response['msg'] == 0){
    316               self.bars[self.distros[self.defaultdistro]].path.setAttribute('stroke',self.progresscolors['ok']);
     337              self.bars[self.activedistro].path.setAttribute('stroke',self.progresscolors['ok']);
    317338            }
    318339            else{
    319              self.bars[self.distros[self.defaultdistro]].path.setAttribute('stroke',self.progresscolors['error']);
     340             self.bars[self.activedistro].path.setAttribute('stroke',self.progresscolors['error']);
    320341           }
    321342           updatebutton.classList.add('btn-success');
    322343           updatebutton.classList.remove('btn-danger');
    323344           updatebutton.innerHTML = 'Update';
     345           svg.classList.remove('loader');
    324346           clearInterval(self.intervalupdate);
    325347         }
     
    335357
    336358
    337 LliurexMirror.prototype.stopUpdate = function stopUpdate(self){
    338   var credentials=[sessionStorage.username , sessionStorage.password];
    339   var n4dclass="MirrorManager";
    340   var n4dmethod="stop_update";
    341   var arglist=[self.distros[self.defaultdistro]];
     359LliurexMirror.prototype.stopUpdate = function stopUpdate(){
     360  var self = this;
     361  var credentials=[sessionStorage.username , sessionStorage.password];
     362  var n4dclass="MirrorManager";
     363  var n4dmethod="stopupdate";
     364  var buttonupdate = document.querySelector('#llxmirrorupdate');
     365  buttonupdate.removeEventListener('click',self._stopUpdate,false);
     366  var arglist=[];
    342367  Utils.n4d(credentials, n4dclass, n4dmethod, arglist, function stopupdate(response){
    343 
     368    console.log(response);
     369    buttonupdate.addEventListener('click',self._updateMirror);
    344370  });
    345371}
Note: See TracChangeset for help on using the changeset viewer.