airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From machris...@apache.org
Subject [3/8] airavata-django-portal git commit: AIRAVATA-2537 Introduce service for loading projects
Date Sun, 15 Oct 2017 19:38:54 GMT
AIRAVATA-2537 Introduce service for loading projects


Project: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/commit/4df20b6e
Tree: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/tree/4df20b6e
Diff: http://git-wip-us.apache.org/repos/asf/airavata-django-portal/diff/4df20b6e

Branch: refs/heads/master
Commit: 4df20b6e16ac7b6a517b66e00640092e8ae0b592
Parents: 30e9ce3
Author: Marcus Christie <machrist@iu.edu>
Authored: Sun Oct 15 12:09:56 2017 -0400
Committer: Marcus Christie <machrist@iu.edu>
Committed: Sun Oct 15 12:09:56 2017 -0400

----------------------------------------------------------------------
 .../js/entry-project-list.js                    |  2 +-
 .../js/services/ProjectService.js               | 55 ++++++++++++++++++++
 .../js/views/ProjectListContainer.vue           | 28 ++++++++--
 3 files changed, 80 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/4df20b6e/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-project-list.js
----------------------------------------------------------------------
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-project-list.js
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-project-list.js
index e130aea..784b7cc 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-project-list.js
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/entry-project-list.js
@@ -5,7 +5,7 @@ new Vue({
   el: '#project-list',
   template: '<project-list-container v-bind:initialProjectsData="projectsData"></project-list-container>',
   data: {
-      projects: null
+      projectsData: null
   },
   components: {
       ProjectListContainer

http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/4df20b6e/django_airavata/apps/workspace/static/django_airavata_workspace/js/services/ProjectService.js
----------------------------------------------------------------------
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/services/ProjectService.js
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/services/ProjectService.js
new file mode 100644
index 0000000..4d51c59
--- /dev/null
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/services/ProjectService.js
@@ -0,0 +1,55 @@
+
+import Project from '../models/Project'
+
+class ProjectService {
+    list(data = {}) {
+        if (data && data.results) {
+            let projects = data.results.map(result => new Project(result));
+            this.next = data.next;
+            this.previous = data.previous;
+            return Promise.resolve({
+                projects: projects,
+                next: this.next,
+                previous: this.previous
+            });
+        } else {
+            return fetch('/api/projects', {
+                credentials: 'include'
+            })
+            .then(response => response.json())
+            .then(json => {
+                this.next = json.next;
+                this.previous = json.previous;
+                let projects = json.results.map(project => new Project(project));
+                return {
+                    projects: projects,
+                    next: this.next,
+                    previous: this.previous
+                }
+            });
+        }
+    }
+
+    listNext() {
+        // TODO
+    }
+
+    listPrevious() {
+        // TODO
+    }
+
+    create() {
+        // TODO
+    }
+
+    update() {
+        // TODO
+    }
+
+    get() {
+        // TODO
+    }
+}
+
+// Export as a singleton
+export default new ProjectService();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata-django-portal/blob/4df20b6e/django_airavata/apps/workspace/static/django_airavata_workspace/js/views/ProjectListContainer.vue
----------------------------------------------------------------------
diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/views/ProjectListContainer.vue
b/django_airavata/apps/workspace/static/django_airavata_workspace/js/views/ProjectListContainer.vue
index 271dd5d..b384a00 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/views/ProjectListContainer.vue
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/views/ProjectListContainer.vue
@@ -11,17 +11,18 @@
 </template>
 
 <script>
-import Project from '../models/Project';
+import Project from '../models/Project'
 import ProjectList from './ProjectList.vue'
+import ProjectService from '../services/ProjectService'
 
 export default {
     props: ['initialProjectsData'],
     name: 'project-list-container',
     data () {
         return {
-            projects: this.initialProjectsData.results,
-            next: this.initialProjectsData.next,
-            previous: this.initialProjectsData.previous,
+            projects: null,
+            next: null,
+            previous: null,
         }
     },
     components: {
@@ -51,6 +52,25 @@ export default {
                 this.projects = json.results.map(project => new Project(project));
             });
         },
+    },
+    beforeMount: function () {
+        if (this.initialProjectsData) {
+            // TODO: Initialize project list iterator
+            ProjectService.list(this.initialProjectsData)
+                .then(result => {
+                    this.projects = result.projects;
+                    this.next = result.next;
+                    this.previous = result.previous;
+                });
+        } else {
+            ProjectService.list()
+                .then(result => {
+                    this.projects = result.projects;
+                    this.next = result.next;
+                    this.previous = result.previous;
+                });
+        }
+        // TODO: load projects if initialProjectsData is null
     }
 }
 </script>


Mime
View raw message