diff options
Diffstat (limited to 'module')
| -rw-r--r-- | module/Api.py | 35 | ||||
| -rw-r--r-- | module/FileManager.py | 17 | ||||
| -rw-r--r-- | module/database/FileDatabase.py | 2 | ||||
| -rw-r--r-- | module/remote/socketbackend/ttypes.py | 32 | ||||
| -rw-r--r-- | module/remote/thriftbackend/pyload.thrift | 14 | ||||
| -rwxr-xr-x | module/remote/thriftbackend/thriftgen/pyload/Pyload-remote | 14 | ||||
| -rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/Pyload.py | 16 | ||||
| -rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/constants.py | 2 | ||||
| -rw-r--r-- | module/remote/thriftbackend/thriftgen/pyload/ttypes.py | 52 | ||||
| -rw-r--r-- | module/web/static/js/collections/FileList.js | 17 | ||||
| -rw-r--r-- | module/web/static/js/collections/PackageList.js | 16 | ||||
| -rw-r--r-- | module/web/static/js/default.js | 13 | ||||
| -rw-r--r-- | module/web/static/js/models/File.js | 33 | ||||
| -rw-r--r-- | module/web/static/js/models/Package.js | 52 | ||||
| -rw-r--r-- | module/web/static/js/models/TreeCollection.js | 38 | ||||
| -rw-r--r-- | module/web/static/js/models/model.js | 24 | ||||
| -rw-r--r-- | module/web/static/js/views/packageTreeView.js | 54 | ||||
| -rw-r--r-- | module/web/templates/default/base.html | 5 | 
18 files changed, 317 insertions, 119 deletions
| diff --git a/module/Api.py b/module/Api.py index 26a6c757f..4671b9cbd 100644 --- a/module/Api.py +++ b/module/Api.py @@ -170,7 +170,7 @@ class Api(Iface):          """pyLoad Core version """          return self.core.version -    @RequirePerm(Permission.Status) +    @RequirePerm(Permission.All)      def statusServer(self):          """Some general information about the current status of pyLoad. @@ -186,17 +186,16 @@ class Api(Iface):          return serverStatus -    @RequirePerm(Permission.Status) +    # TODO: user sensitive pausing, now only available for admins +      def pauseServer(self):          """Pause server: It won't start any new downloads, but nothing gets aborted."""          self.core.threadManager.pause = True -    @RequirePerm(Permission.Status)      def unpauseServer(self):          """Unpause server: New Downloads will be started."""          self.core.threadManager.pause = False -    @RequirePerm(Permission.Status)      def togglePause(self):          """Toggle pause state. @@ -205,7 +204,6 @@ class Api(Iface):          self.core.threadManager.pause ^= True          return self.core.threadManager.pause -    @RequirePerm(Permission.Status)      def toggleReconnect(self):          """Toggle reconnect activation. @@ -214,7 +212,6 @@ class Api(Iface):          self.core.config["reconnect"]["activated"] ^= True          return self.core.config["reconnect"]["activated"] -    @RequirePerm(Permission.Status)      def freeSpace(self):          """Available free space at download directory in bytes"""          return free_space(self.core.config["general"]["download_folder"]) @@ -245,7 +242,7 @@ class Api(Iface):          except:              return ['No log available'] -    @RequirePerm(Permission.Status) +    @RequirePerm(Permission.All)      def isTimeDownload(self):          """Checks if pyload will start new downloads according to time in config. @@ -255,7 +252,7 @@ class Api(Iface):          end = self.core.config['downloadTime']['end'].split(":")          return compare_time(start, end) -    @RequirePerm(Permission.Status) +    @RequirePerm(Permission.All)      def isTimeReconnect(self):          """Checks if pyload will try to make a reconnect @@ -269,7 +266,7 @@ class Api(Iface):      def scanDownloadFolder(self):          pass -    @RequirePerm(Permission.Status) +    @RequirePerm(Permission.All)      def getProgressInfo(self):          """ Status of all currently running tasks @@ -512,12 +509,12 @@ class Api(Iface):          :return: package id          """ -        self.addPackageChild(name, links, password, -1, False) +        return self.addPackageChild(name, links, password, -1, False)      @RequirePerm(Permission.Add)      def addPackageP(self, name, links, password, paused):          """ Same as above with additional paused attribute. """ -        self.addPackageChild(name, links, password, -1, paused) +        return self.addPackageChild(name, links, password, -1, paused)      @RequirePerm(Permission.Add)      def addPackageChild(self, name, links, password, root, paused): @@ -618,7 +615,7 @@ class Api(Iface):          pass      ############################# -    #  File Information retrival +    #  File Information retrieval      #############################      @RequirePerm(Permission.All) @@ -638,9 +635,9 @@ class Api(Iface):          :param pid: package id          :param full: go down the complete tree or only the first layer -        :return: :class:`PackageView` +        :return: :class:`TreeCollection`          """ -        return self.core.files.getView(pid, full, False) +        return self.core.files.getTree(pid, full, False)      @RequirePerm(Permission.All)      def getUnfinishedFileTree(self, pid, full): @@ -648,9 +645,9 @@ class Api(Iface):          :param pid: package id          :param full: go down the complete tree or only the first layer -        :return: :class:`PackageView` +        :return: :class:`TreeCollection`          """ -        return self.core.files.getView(pid, full, False) +        return self.core.files.getTree(pid, full, False)      @RequirePerm(Permission.All)      def getPackageContent(self, pid): @@ -876,13 +873,13 @@ class Api(Iface):      #  Event Handling      ############################# -    @RequirePerm(Permission.Status)      def getEvents(self, uuid):          """Lists occurred events, may be affected to changes in future.          :param uuid: self assigned string uuid which has to be unique          :return: list of `Events`          """ +        # TODO: permissions?          # TODO          pass @@ -1030,7 +1027,8 @@ class Api(Iface):          except Exception, e:              raise ServiceException(e.message) -    @RequirePerm(Permission.Status) + +    #TODO: permissions      def getAllInfo(self):          """Returns all information stored by addon plugins. Values are always strings @@ -1038,7 +1036,6 @@ class Api(Iface):          """          return self.core.addonManager.getAllInfo() -    @RequirePerm(Permission.Status)      def getInfoByPlugin(self, plugin):          """Returns information stored by a specific plugin. diff --git a/module/FileManager.py b/module/FileManager.py index 9d3c9a9cc..8a6ae75d0 100644 --- a/module/FileManager.py +++ b/module/FileManager.py @@ -21,9 +21,9 @@ from threading import RLock  from module.utils import lock -from Api import PackageStatus, DownloadStatus as DS, PackageView, PackageDoesNotExists -from datatypes import PyFile, PyPackage -from datatypes.PyPackage import RootPackage +from Api import PackageStatus, DownloadStatus as DS, TreeCollection, PackageDoesNotExists +from datatypes.PyFile import PyFile +from datatypes.PyPackage import PyPackage, RootPackage  # invalidates the cache  def invalidate(func): @@ -142,6 +142,7 @@ class FileManager:          if not pack: return None +        # todo: what does this todo mean?!          #todo: fill child packs and files          packs = self.db.getAllPackages(root=pid)          if pid in packs: del packs[pid] @@ -174,13 +175,13 @@ class FileManager:          return self.db.getFileInfo(fid)      @lock -    def getView(self, pid, full, unfinished): -        """  return a PackageView and fill the info data of containing packages. +    def getTree(self, pid, full, unfinished): +        """  return a TreeCollection and fill the info data of containing packages.               optional filter only unfnished files          """ -        view = PackageView(pid) +        view = TreeCollection(pid) -        # for depth=1, we dont need to retrieve all files/packages +        # for depth=1, we don't need to retrieve all files/packages          root = pid if not full else None          packs = self.db.getAllPackages(root) @@ -191,7 +192,7 @@ class FileManager:              if fid in files:                  files[fid] = f.toInfoData() -        # foreign pid, dont overwrite local pid ! +        # foreign pid, don't overwrite local pid !          for fpid, p in self.packages.iteritems():              if fpid in packs:                  # copy the stats data diff --git a/module/database/FileDatabase.py b/module/database/FileDatabase.py index 80da775c7..ab681dc7f 100644 --- a/module/database/FileDatabase.py +++ b/module/database/FileDatabase.py @@ -40,7 +40,7 @@ class FileMethods(DatabaseMethods):      def processcount(self, fid, user=None):          """ number of files which have to be processed """          # status in online, queued, starting, waiting, downloading -        self.c.execute("SELECT COUNT(*) FROM files as WHERE dlstatus IN (2,3,8,9,10) AND fid != ?", (str(fid), )) +        self.c.execute("SELECT COUNT(*) FROM files WHERE dlstatus IN (2,3,8,9,10) AND fid != ?", (fid, ))          return self.c.fetchone()[0]      # TODO: think about multiuser side effects on *count methods diff --git a/module/remote/socketbackend/ttypes.py b/module/remote/socketbackend/ttypes.py index b7e0d7f3d..569c758fe 100644 --- a/module/remote/socketbackend/ttypes.py +++ b/module/remote/socketbackend/ttypes.py @@ -32,15 +32,15 @@ class FileStatus:  class Input:  	Bool = 4 -	Choice = 6  	Click = 5  	List = 8  	Multiple = 7  	NA = 0  	Password = 3 +	Select = 6  	Table = 9  	Text = 1 -	TextBox = 2 +	Textbox = 2  class MediaType:  	All = 0 @@ -58,20 +58,20 @@ class Output:  	Query = 4  class PackageStatus: +	Folder = 2  	Ok = 0  	Paused = 1 -	Remote = 2 +	Remote = 3  class Permission: -	Accounts = 32 +	Accounts = 16  	Add = 1 -	Addons = 128 +	Addons = 64  	All = 0  	Delete = 2 -	Download = 16 -	Interaction = 64 +	Download = 8 +	Interaction = 32  	Modify = 4 -	Status = 8  class Role:  	Admin = 0 @@ -237,14 +237,6 @@ class PackageStats(BaseObject):  		self.sizetotal = sizetotal  		self.sizedone = sizedone -class PackageView(BaseObject): -	__slots__ = ['root', 'files', 'packages'] - -	def __init__(self, root=None, files=None, packages=None): -		self.root = root -		self.files = files -		self.packages = packages -  class ProgressInfo(BaseObject):  	__slots__ = ['fid', 'name', 'speed', 'eta', 'format_eta', 'bleft', 'size', 'format_size', 'percent', 'status', 'statusmsg', 'format_wait', 'wait_until', 'packageID', 'packageName', 'plugin'] @@ -291,6 +283,14 @@ class ServiceException(Exception):  	def __init__(self, msg=None):  		self.msg = msg +class TreeCollection(BaseObject): +	__slots__ = ['root', 'files', 'packages'] + +	def __init__(self, root=None, files=None, packages=None): +		self.root = root +		self.files = files +		self.packages = packages +  class UserData(BaseObject):  	__slots__ = ['uid', 'name', 'email', 'role', 'permission', 'folder', 'traffic', 'dllimit', 'dlquota', 'hddquota', 'user', 'templateName'] diff --git a/module/remote/thriftbackend/pyload.thrift b/module/remote/thriftbackend/pyload.thrift index c628dff78..23b39fada 100644 --- a/module/remote/thriftbackend/pyload.thrift +++ b/module/remote/thriftbackend/pyload.thrift @@ -175,7 +175,7 @@ struct PackageInfo {  }  // thrift does not allow recursive datatypes, so all data is accumulated and mapped with id -struct PackageView { +struct TreeCollection {    1: PackageInfo root,    2: map<FileID, FileInfo> files,    3: map<PackageID, PackageInfo> packages @@ -385,19 +385,19 @@ service Pyload {    // File Information retrival    //////////////////////////// -  PackageView getAllFiles(), -  PackageView getAllUnfinishedFiles(), +  TreeCollection getAllFiles(), +  TreeCollection getAllUnfinishedFiles(),    // pid -1 for root, full=False only delivers first level in tree -  PackageView getFileTree(1: PackageID pid, 2: bool full), -  PackageView getUnfinishedFileTree(1: PackageID pid, 2: bool full), +  TreeCollection getFileTree(1: PackageID pid, 2: bool full), +  TreeCollection getUnfinishedFileTree(1: PackageID pid, 2: bool full),    // same as above with full=False -  PackageView getPackageContent(1: PackageID pid), +  TreeCollection getPackageContent(1: PackageID pid),    PackageInfo getPackageInfo(1: PackageID pid) throws (1: PackageDoesNotExists e),    FileInfo getFileInfo(1: FileID fid) throws (1: FileDoesNotExists e), -  map<FileID, FileInfo> findFiles(1: string pattern), +  TreeCollection findFiles(1: string pattern),    ///////////////////////    // Modify Downloads diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote index 5b4a6fc75..a84de7978 100755 --- a/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote +++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload-remote @@ -1,6 +1,6 @@  #!/usr/bin/env python  # -# Autogenerated by Thrift Compiler (0.9.0-dev) +# Autogenerated by Thrift Compiler (0.8.0)  #  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  # @@ -64,14 +64,14 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':    print '  void renameCollPack(string name, string new_name)'    print '  void deleteCollPack(string name)'    print '  void deleteCollLink(string url)' -  print '  PackageView getAllFiles()' -  print '  PackageView getAllUnfinishedFiles()' -  print '  PackageView getFileTree(PackageID pid, bool full)' -  print '  PackageView getUnfinishedFileTree(PackageID pid, bool full)' -  print '  PackageView getPackageContent(PackageID pid)' +  print '  TreeCollection getAllFiles()' +  print '  TreeCollection getAllUnfinishedFiles()' +  print '  TreeCollection getFileTree(PackageID pid, bool full)' +  print '  TreeCollection getUnfinishedFileTree(PackageID pid, bool full)' +  print '  TreeCollection getPackageContent(PackageID pid)'    print '  PackageInfo getPackageInfo(PackageID pid)'    print '  FileInfo getFileInfo(FileID fid)' -  print '   findFiles(string pattern)' +  print '  TreeCollection findFiles(string pattern)'    print '  void restartPackage(PackageID pid)'    print '  void restartFile(FileID fid)'    print '  void recheckPackage(PackageID pid)' diff --git a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py index ba5d8cadc..c807d3d9e 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/Pyload.py +++ b/module/remote/thriftbackend/thriftgen/pyload/Pyload.py @@ -1,5 +1,5 @@  # -# Autogenerated by Thrift Compiler (0.9.0-dev) +# Autogenerated by Thrift Compiler (0.8.0)  #  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  # @@ -8,7 +8,7 @@  from thrift.Thrift import TType, TMessageType, TException  from ttypes import * -from thrift.Thrift import TProcessor +from thrift.Thrift import TProcessor, TApplicationException  from thrift.protocol.TBase import TBase, TExceptionBase @@ -5636,7 +5636,7 @@ class getAllFiles_result(TBase):     ]    thrift_spec = ( -    (0, TType.STRUCT, 'success', (PackageView, PackageView.thrift_spec), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): @@ -5663,7 +5663,7 @@ class getAllUnfinishedFiles_result(TBase):     ]    thrift_spec = ( -    (0, TType.STRUCT, 'success', (PackageView, PackageView.thrift_spec), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): @@ -5704,7 +5704,7 @@ class getFileTree_result(TBase):     ]    thrift_spec = ( -    (0, TType.STRUCT, 'success', (PackageView, PackageView.thrift_spec), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): @@ -5745,7 +5745,7 @@ class getUnfinishedFileTree_result(TBase):     ]    thrift_spec = ( -    (0, TType.STRUCT, 'success', (PackageView, PackageView.thrift_spec), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): @@ -5782,7 +5782,7 @@ class getPackageContent_result(TBase):     ]    thrift_spec = ( -    (0, TType.STRUCT, 'success', (PackageView, PackageView.thrift_spec), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): @@ -5901,7 +5901,7 @@ class findFiles_result(TBase):     ]    thrift_spec = ( -    (0, TType.MAP, 'success', (TType.I32,None,TType.STRUCT,(FileInfo, FileInfo.thrift_spec)), None, ), # 0 +    (0, TType.STRUCT, 'success', (TreeCollection, TreeCollection.thrift_spec), None, ), # 0    )    def __init__(self, success=None,): diff --git a/module/remote/thriftbackend/thriftgen/pyload/constants.py b/module/remote/thriftbackend/thriftgen/pyload/constants.py index f8960dc63..7842b3177 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/constants.py +++ b/module/remote/thriftbackend/thriftgen/pyload/constants.py @@ -1,5 +1,5 @@  # -# Autogenerated by Thrift Compiler (0.9.0-dev) +# Autogenerated by Thrift Compiler (0.8.0)  #  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  # diff --git a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py index 3e4cce276..b61d4c479 100644 --- a/module/remote/thriftbackend/thriftgen/pyload/ttypes.py +++ b/module/remote/thriftbackend/thriftgen/pyload/ttypes.py @@ -1,5 +1,5 @@  # -# Autogenerated by Thrift Compiler (0.9.0-dev) +# Autogenerated by Thrift Compiler (0.8.0)  #  # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING  # @@ -119,28 +119,31 @@ class FileStatus(TBase):  class PackageStatus(TBase):    Ok = 0    Paused = 1 -  Remote = 2 +  Folder = 2 +  Remote = 3    _VALUES_TO_NAMES = {      0: "Ok",      1: "Paused", -    2: "Remote", +    2: "Folder", +    3: "Remote",    }    _NAMES_TO_VALUES = {      "Ok": 0,      "Paused": 1, -    "Remote": 2, +    "Folder": 2, +    "Remote": 3,    }  class Input(TBase):    NA = 0    Text = 1 -  TextBox = 2 +  Textbox = 2    Password = 3    Bool = 4    Click = 5 -  Choice = 6 +  Select = 6    Multiple = 7    List = 8    Table = 9 @@ -148,11 +151,11 @@ class Input(TBase):    _VALUES_TO_NAMES = {      0: "NA",      1: "Text", -    2: "TextBox", +    2: "Textbox",      3: "Password",      4: "Bool",      5: "Click", -    6: "Choice", +    6: "Select",      7: "Multiple",      8: "List",      9: "Table", @@ -161,11 +164,11 @@ class Input(TBase):    _NAMES_TO_VALUES = {      "NA": 0,      "Text": 1, -    "TextBox": 2, +    "Textbox": 2,      "Password": 3,      "Bool": 4,      "Click": 5, -    "Choice": 6, +    "Select": 6,      "Multiple": 7,      "List": 8,      "Table": 9, @@ -196,22 +199,20 @@ class Permission(TBase):    Add = 1    Delete = 2    Modify = 4 -  Status = 8 -  Download = 16 -  Accounts = 32 -  Interaction = 64 -  Addons = 128 +  Download = 8 +  Accounts = 16 +  Interaction = 32 +  Addons = 64    _VALUES_TO_NAMES = {      0: "All",      1: "Add",      2: "Delete",      4: "Modify", -    8: "Status", -    16: "Download", -    32: "Accounts", -    64: "Interaction", -    128: "Addons", +    8: "Download", +    16: "Accounts", +    32: "Interaction", +    64: "Addons",    }    _NAMES_TO_VALUES = { @@ -219,11 +220,10 @@ class Permission(TBase):      "Add": 1,      "Delete": 2,      "Modify": 4, -    "Status": 8, -    "Download": 16, -    "Accounts": 32, -    "Interaction": 64, -    "Addons": 128, +    "Download": 8, +    "Accounts": 16, +    "Interaction": 32, +    "Addons": 64,    }  class Role(TBase): @@ -559,7 +559,7 @@ class PackageInfo(TBase):      self.pids = pids -class PackageView(TBase): +class TreeCollection(TBase):    """    Attributes:     - root diff --git a/module/web/static/js/collections/FileList.js b/module/web/static/js/collections/FileList.js new file mode 100644 index 000000000..e91088867 --- /dev/null +++ b/module/web/static/js/collections/FileList.js @@ -0,0 +1,17 @@ +define(['jquery', 'backbone', 'underscore', 'models/File'], function($, Backbone, _, File) { + +    return Backbone.Collection.extend({ + +        model: File, + +        comparator: function(file) { +            return file.get('fileorder'); +        }, + +        initialize: function() { + +        } + +    }); + +});
\ No newline at end of file diff --git a/module/web/static/js/collections/PackageList.js b/module/web/static/js/collections/PackageList.js new file mode 100644 index 000000000..cb8abe22f --- /dev/null +++ b/module/web/static/js/collections/PackageList.js @@ -0,0 +1,16 @@ +define(['jquery', 'backbone', 'underscore', 'models/Package'], function($, Backbone, _, Package) { + +    return Backbone.Collection.extend({ + +        model: Package, + +        comparator: function(pack) { +            return pack.get('packageorder'); +        }, + +        initialize: function() { + +        } + +    }); +});
\ No newline at end of file diff --git a/module/web/static/js/default.js b/module/web/static/js/default.js index 3ec133a87..bed397712 100644 --- a/module/web/static/js/default.js +++ b/module/web/static/js/default.js @@ -31,12 +31,21 @@ require.config({  }); -define('default', ['jquery', 'backbone', 'routers/defaultRouter', 'views/headerView'], function ($, Backbone, DefaultRouter, HeaderView) { +define('default', ['jquery', 'backbone', 'routers/defaultRouter', 'views/headerView', 'views/packageTreeView'], +    function ($, Backbone, DefaultRouter, HeaderView, TreeView) { +      var init = function(){          var view = new HeaderView();          view.render();      }; -   return {"init":init}; +    var initPackageTree = function() { +        $(function() { +            var view = new TreeView(); +            view.init(); +        }); +    }; + +   return {"init":init, "initPackageTree": initPackageTree};  });
\ No newline at end of file diff --git a/module/web/static/js/models/File.js b/module/web/static/js/models/File.js new file mode 100644 index 000000000..71aa2b84f --- /dev/null +++ b/module/web/static/js/models/File.js @@ -0,0 +1,33 @@ +define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { + +    return Backbone.Model.extend({ + +        idAttribute: 'fid', + +        defaults: { +            fid: -1, +            name: null, +            package: -1, +            owner: -1, +            size: -1, +            status: -1, +            media: -1, +            added: -1, +            fileorder: -1, +            download: null +        }, + + +        // Model Constructor +        initialize: function() { + +        }, + +        // Any time a model attribute is set, this method is called +        validate: function(attrs) { + +        } + +    }); + +});
\ No newline at end of file diff --git a/module/web/static/js/models/Package.js b/module/web/static/js/models/Package.js new file mode 100644 index 000000000..e5b0dc5a7 --- /dev/null +++ b/module/web/static/js/models/Package.js @@ -0,0 +1,52 @@ +define(['jquery', 'backbone', 'underscore'], function($, Backbone, _) { + +    return Backbone.Model.extend({ + +        idAttribute: 'pid', + +        defaults: { +            pid: -1, +            name : null, +            folder: "", +            root: -1, +            owner: -1, +            site: "", +            comment: "", +            password: "", +            added: -1, +            status: -1, +            packageorder: -1, +            stats: null, +            fids: null, +            pids: null, +            files: null, // Collection +            packs: null // Collection +        }, + +        // Model Constructor +        initialize: function() { + +        }, + +        // Changes url + method and delegates call to super class +        fetch: function(options) { +            options || (options = {}); +            options.url = 'api/getPackageInfo/' + this.get('pid'); +            options.type = "post"; + +            return Backbone.Model.prototype.fetch.call(options); + +        }, + +        save: function(options) { +            // TODO +        }, + +        // Any time a model attribute is set, this method is called +        validate: function(attrs) { + +        } + +    }); + +});
\ No newline at end of file diff --git a/module/web/static/js/models/TreeCollection.js b/module/web/static/js/models/TreeCollection.js new file mode 100644 index 000000000..6476ea7b5 --- /dev/null +++ b/module/web/static/js/models/TreeCollection.js @@ -0,0 +1,38 @@ +define(['jquery', 'backbone', 'underscore', 'models/Package', 'collections/FileList', 'collections/PackageList'], +    function($, Backbone, _, Package, FileList, PackageList) { + +    // TreeCollection +    // A Model and not a collection, aggregates other collections +    return Backbone.Model.extend({ + +        defaults : { +            root: null, +            packages: null, +            files: null +        }, + +        initialize: function() { + +        }, + +        fetch: function(options) { +            options || (options = {}); +            var pid = options.pid || -1; + +            // TODO: more options possible +            options.url = 'api/getFileTree/' + pid + '/false'; +            options.type = "post"; + +            return Backbone.Model.prototype.fetch.call(this, options); +        }, + +        parse: function(resp, xhr) { +            return { +              root: new Package(resp.root), +              packages: new PackageList(_.values(resp.packages)), +              files: new FileList(_.values(resp.files)) +            }; +        } + +    }); +});
\ No newline at end of file diff --git a/module/web/static/js/models/model.js b/module/web/static/js/models/model.js deleted file mode 100644 index cd92e2644..000000000 --- a/module/web/static/js/models/model.js +++ /dev/null @@ -1,24 +0,0 @@ -define(['jquery', 'backbone'], function($, Backbone) { - -    var Model = Backbone.Model.extend({ - -            defaults: { -                message: "You are now using Backbone, Lodash, Require, Modernizr, and jQuery! (Click Me)" -            }, - -            // Model Constructor -            initialize: function() { - -            }, - -            // Any time a model attribute is set, this method is called -            validate: function(attrs) { - -            } - -    }); - -    // Returns the Model class -    return Model; - -});
\ No newline at end of file diff --git a/module/web/static/js/views/packageTreeView.js b/module/web/static/js/views/packageTreeView.js new file mode 100644 index 000000000..79527b394 --- /dev/null +++ b/module/web/static/js/views/packageTreeView.js @@ -0,0 +1,54 @@ +define(['jquery', 'backbone', 'underscore', 'models/TreeCollection'], function($, Backbone, _, TreeCollection){ + +    // Renders whole PackageView +    return Backbone.View.extend({ + +        el: '#content', + +        events: { + +        }, + +        initialize: function() { +            _.bindAll(this, 'render'); + +            this.tree = new TreeCollection(); + +        }, + +        init: function() { +            var self = this; +            this.tree.fetch({success: function(){ +                self.render(); +            }}); +        }, + + +        render: function() { + +            var packs = this.tree.get('packages'), +                files = this.tree.get('files'), +                html = 'Root: ' +  this.tree.get('root').get('name') + '<br>'; + +            html += 'Packages: ' + packs.size(); +            html += '<br><ul>'; + +            packs.each(function(pack){ +                html += '<li>'+ pack.get('pid') + pack.get('name') + '</li>'; +            }); + +            html += '</ul><br> Files: ' + files.size() + '<br><ul>'; +            files.each(function(file){ +                html += '<li>'+ file.get('fid') + file.get('name') + '</li>'; +            }); + +            html += '</ul>'; + + +            this.$el.html(html); + +            return this; +        } + +    }); +});
\ No newline at end of file diff --git a/module/web/templates/default/base.html b/module/web/templates/default/base.html index 316cc04af..f1f779760 100644 --- a/module/web/templates/default/base.html +++ b/module/web/templates/default/base.html @@ -19,6 +19,7 @@      <script>
          require(['default'], function (App) {
              App.init();
 +            App.initPackageTree();
          });
      </script>
 @@ -64,6 +65,10 @@          </div>
      </header>
      <div id="content">
 +        {% for msg in messages %}
 +            <p>{{ msg }}</p>
 +        {% endfor %}
 +
          <div class="modal window-container zoomout ow-closed">
              <h1>Close me!</h1>
              <a class='close-button' href='#'>X</a>
 | 
