Преглед изворни кода

HUE-2033 [core] Link back backend to homepage 2

Romain Rigaux пре 11 година
родитељ
комит
38f1ed3

+ 1 - 1
apps/pig/src/pig/api.py

@@ -62,7 +62,7 @@ class OozieApi:
       oozie_wf = _submit_workflow(self.user, self.fs, self.jt, workflow, mapping)
     finally:
       if workflow:
-        workflow.delete()
+        workflow.delete(skip_trash=True)
 
     return oozie_wf
 

+ 80 - 29
desktop/core/src/desktop/api.py

@@ -51,24 +51,44 @@ def list_tags(request):
   tags = list(set([tag for doc in docs for tag in doc.tags.all()] + [tag for tag in DocumentTag.objects.get_tags(user=request.user)])) # List of all personal and share tags
   return HttpResponse(json.dumps(massaged_tags_for_json(tags, request.user)), mimetype="application/json")
 
-def massaged_tags_for_json2(tags, user):
+def massaged_tags_for_json2(docs, user):
+  """
+    var TAGS_DEFAULTS = {
+    'history': {'name': 'History', 'id': 1, 'docs': [1], 'type': 'history'},
+    'trash': {'name': 'Trash', 'id': 3, 'docs': [2]},
+    'mine': [{'name': 'default', 'id': 2, 'docs': [3]}, {'name': 'web', 'id': 3, 'docs': [3]}],
+    'notmine': [{'name': 'example', 'id': 20, 'docs': [10]}, {'name': 'ex2', 'id': 30, 'docs': [10, 11]}]
+  };        
+  """  
   ts = {
-    'trash': [],
-    'history': [],
+    'trash': {},
+    'history': {},
     'mine': [],
     'notmine': [],
   }
+  sharers = defaultdict(list)
   
-  ts['trash'].append(massaged_tags(DocumentTag.objects.get_trash_tag(user)))
-  ts['history'].append(massaged_tags(DocumentTag.objects.get_history_tag(user)))
+  trash_tag = DocumentTag.objects.get_trash_tag(user)
+  history_tag = DocumentTag.objects.get_history_tag(user)
+  ts['trash'] = massaged_tags(trash_tag)
+  ts['history'] = massaged_tags(history_tag)
+
+  tags = list(set([tag for doc in docs for tag in doc.tags.all()] + [tag for tag in DocumentTag.objects.get_tags(user=user)])) # List of all personal and share tags
 
   for tag in tags:
     massaged_tag = massaged_tags(tag)
-    if tag.owner == user:
+    if tag == trash_tag:
+      ts['trash'] = massaged_tag
+    elif tag == history_tag:
+      ts['history'] = massaged_tag    
+    elif tag.owner == user:
       ts['mine'].append(massaged_tag)
     else:
-      ts['notmine'].append(massaged_tag)
+      sharers[tag.owner].append(massaged_tag)
+  
+  ts['notmine'] = [{'name': sharer.username, 'projects': projects} for sharer, projects in sharers.iteritems()]
 
+  print ts
   return ts
 
 def massaged_tags(tag):
@@ -76,33 +96,64 @@ def massaged_tags(tag):
     'id': tag.id,
     'name': tag.tag,
     'owner': tag.owner.username,
+    'docs': list(tag.document_set.exclude(name='pig-app-hue-script').values_list('id', flat=True)) # Could get with one request groupy
   }
 
 def massaged_documents_for_json2(documents, user):
-  docs = {'mydocs': defaultdict(list), 'shared_docs': defaultdict(list),}
-  tags = {}
-  
-  trash_tag = DocumentTag.objects.get_trash_tag(user)
-  history_tag = DocumentTag.objects.get_history_tag(user)
+  """
+  var DOCUMENTS_DEFAULTS = {
+    '1': {
+      'id': 1,
+      'name': 'my query history', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
+      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
+    },
+    '2': {
+      'id': 2,
+      'name': 'my query 2 trashed', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
+      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
+     },
+     '3': {
+       'id': 3,
+       'name': 'my query 3 tagged twice', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
+     'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
+     },
+    '10': {
+      'id': 10,
+      'name': 'my query 3 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
+      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
+     },
+    '11': {
+      'id': 11,
+      'name': 'my query 4 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
+      'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
+     }
+  };
+  """
+  docs = {}
   
-  tags[trash_tag.id] = {'owner': trash_tag.owner.username, 'owner_id': trash_tag.owner.id, 'name': trash_tag.tag}
-  tags[history_tag.id] = {'owner': history_tag.owner.username, 'owner_id': history_tag.owner.id, 'name': history_tag.tag}
+  for document in documents:
+    perms = document.list_permissions()
+    docs[document.id] = {
+      'id': document.id,
+      'contentType': document.content_type.name,
+      'icon': document.icon,
+      'name': document.name,
+      'url': document.content_object.get_absolute_url(),
+      'description': document.description,
+      'tags': [{'id': tag.id, 'name': tag.tag} for tag in document.tags.all()],
+      'perms': { # un-used so far
+        'read': {
+          'users': [{'id': user.id, 'username': user.username} for user in perms.users.all()],
+          'groups': [{'id': group.id, 'name': group.name} for group in perms.groups.all()]
+        }
+      },
+      'owner': document.owner.username,
+      'isMine': document.owner.username == user.username,
+      'lastModified': document.last_modified.strftime("%x %X"),
+      'lastModifiedInMillis': time.mktime(document.last_modified.timetuple())
+   }
   
-  for doc in documents:
-    if doc.is_trashed():
-      docs['mydocs'][trash_tag.id].append(massage_doc_for_json2(doc))
-    elif doc.is_historic():
-      docs['mydocs'][history_tag.id].append(massage_doc_for_json2(doc))   
-    elif doc.owner.username == user.username: 
-      for tag in doc.tags.all():
-        docs['mydocs'][tag.id].append(massage_doc_for_json2(doc))
-        tags[tag.id] = {'owner': tag.owner.username, 'owner_id': tag.owner.id, 'name': tag.tag} 
-    else:
-      for tag in doc.tags.all():
-        docs['shared_docs'][tag.id].append(massage_doc_for_json2(doc)) 
-        tags[tag.id] = {'owner': tag.owner.username, 'owner_id': tag.owner.id, 'name': tag.tag}
-      
-  return {'docs': docs, 'tags': tags}
+  return docs
 
 
 def massage_doc_for_json2(doc):

+ 6 - 0
desktop/core/src/desktop/models.py

@@ -200,6 +200,12 @@ class DocumentManager(models.Manager):
 
     return Document.objects.get_docs(user, model_class).exclude(tags__in=exclude).order_by('-last_modified')
 
+  def history_docs(self, model_class, user):
+    include = [DocumentTag.objects.get_history_tag(user=user)]
+    exclude = [DocumentTag.objects.get_trash_tag(user=user)]    
+
+    return Document.objects.get_docs(user, model_class).filter(tags__in=include).exclude(tags__in=exclude).order_by('-last_modified')
+
   def available(self, model_class, user, with_history=False):
     docs = self.available_docs(model_class, user, with_history)
 

+ 14 - 4
desktop/core/src/desktop/templates/home2.mako

@@ -134,7 +134,7 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
           <li class="nav-header tag-shared-header">
             ${_('Shared with me')}
           </li>
-          <div data-bind="template: { name: 'tag-template', foreach: sharedTags }"></div>
+          <div data-bind="template: { name: 'tag-sharer-template', foreach: sharedTags }"></div>          
           <li data-bind="visible: sharedTags().length == 0">
             <a href="javascript:void(0)" style="line-height:24px"><i class="fa fa-plus-circle"></i> ${_('There are currently no projects shared with you.')}
             </a>
@@ -189,8 +189,8 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
     <td><a data-bind="attr: { href: url }, text: name"></a></td>
     <td></td>
     <td>
-      <div class="documentTags">
-        <span class="badge">history</span>
+      <div class="documentTags" data-bind="foreach: tags">
+        <span class="badge" data-bind="text: name"></span>
       </div>
     </td>
     <td data-bind="text: owner"></td>
@@ -228,10 +228,20 @@ ${ commonheader(_('Welcome Home'), "home", user) | n,unicode }
 </div>
 
 
+<script type="text/html" id="tag-sharer-template">
+  <div style="margin-right:10px;margin-bottom: 6px;float:left;">
+    <span class="tags-modal-checkbox badge">
+       <i class="fa fa-trash-o"></i> <span data-bind="text: name"></span>
+    </span>
+    <div data-bind="template: { name: 'tag-template', foreach: projects }"></div>
+  </div>
+</script>
+
+
 <script type="text/html" id="tag-edit-template">
   <div style="margin-right:10px;margin-bottom: 6px;float:left;">
     <span class="tags-modal-checkbox badge">
-       <i class="fa fa-trash-o hide"></i> <span data-bind="text: name"></span>
+       <i class="fa fa-trash-o"></i> <span data-bind="text: name"></span>
     </span>
   </div>
 </script>

+ 6 - 9
desktop/core/src/desktop/views.py

@@ -49,25 +49,22 @@ from desktop.api import massaged_tags_for_json, massaged_documents_for_json, mas
 
 LOG = logging.getLogger(__name__)
 
+
 def home2(request):
+  history_tag = DocumentTag.objects.get_history_tag(request.user)  
+  trash_tag = DocumentTag.objects.get_trash_tag(request.user)
   docs = itertools.chain(
-      Document.objects.get_docs(request.user).order_by('-last_modified').exclude(tags__tag__in=['history'])[:500],
-      Document.objects.get_docs(request.user).order_by('-last_modified').filter(tags__tag__in=['history'])[:100]
+      Document.objects.get_docs(request.user).exclude(tags__in=[trash_tag]).filter(tags__in=[history_tag]).order_by('-last_modified')[:500],
+      Document.objects.get_docs(request.user).exclude(tags__in=[history_tag]).order_by('-last_modified')[:100]
   )
   docs = list(docs)
-  tags = list(set([tag for doc in docs for tag in doc.tags.all()])) # List of all personal and shared tags
 
   apps = appmanager.get_apps_dict(request.user)
 
-  #print json.dumps(massaged_documents_for_json2(docs, request.user))
-#  for a, v in massaged_documents_for_json2(docs, request.user)['docs']['mydocs'].iteritems():
-#    print a
-#    print v
   return render('home2.mako', request, {
     'apps': apps,
-    'documents': massaged_documents_for_json2(docs, request.user),
     'json_documents': json.dumps(massaged_documents_for_json2(docs, request.user)),
-    'json_tags': json.dumps(massaged_tags_for_json2(tags, request.user))
+    'json_tags': json.dumps(massaged_tags_for_json2(docs, request.user))
   })
 
 def home(request):

+ 10 - 6
desktop/core/static/js/home.vm.js

@@ -18,14 +18,17 @@
 function HomeViewModel(json_tags, json_docs) {
   var self = this;
 
-  var TAGS_DEFAULTS = {
+  var MOCK_TAGS = {
     'history': {'name': 'History', 'id': 1, 'docs': [1], 'type': 'history'},
     'trash': {'name': 'Trash', 'id': 3, 'docs': [2]},
     'mine': [{'name': 'default', 'id': 2, 'docs': [3]}, {'name': 'web', 'id': 3, 'docs': [3]}],
-    'notmine': [{'name': 'example', 'id': 20, 'docs': [10]}, {'name': 'ex2', 'id': 30, 'docs': [10, 11]}]
+    'notmine': [
+       {'name': 'romain', 'projects': [{'name': 'example', 'id': 20, 'docs': [10]}, {'name': 'ex2', 'id': 30, 'docs': [10, 11]}]},
+       {'name': 'pai', 'projects': [{'name': 'example2', 'id': 20, 'docs': [10]}]}
+     ]
   };
 
-  var DOCUMENTS_DEFAULTS = {
+  var MOCK_DOCUMENTS = {
     '1': {
       'id': 1,
       'name': 'my query history', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
@@ -54,8 +57,9 @@ function HomeViewModel(json_tags, json_docs) {
   };
 
 
-  self.tags = ko.mapping.fromJS(TAGS_DEFAULTS);
-  self.documents = ko.observableArray([]);
+  var ALL_DOCUMENTS = json_docs;
+  self.tags = ko.mapping.fromJS(json_tags);
+  self.documents = ko.observableArray([]);  
   
   self.editTagsToCreate = ko.observableArray([]);
   self.editTagsToDelete = ko.observableArray([]);
@@ -78,7 +82,7 @@ function HomeViewModel(json_tags, json_docs) {
 
   self.filterDocs = function(tag) {
     self.documents.removeAll();
-    $.each(DOCUMENTS_DEFAULTS, function(id, doc) {
+    $.each(ALL_DOCUMENTS, function(id, doc) {
       if (tag.docs().indexOf(parseInt(id)) != -1) { // Beware, keys are strings in js
     	self.documents.push(doc); // pushall?
       }