home.vm.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Licensed to Cloudera, Inc. under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. Cloudera, Inc. licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. function HomeViewModel(json_tags, json_docs) {
  17. var self = this;
  18. var TAGS_DEFAULTS = {
  19. 'history': {'name': 'History', 'id': 1, 'docs': [1], 'type': 'history'},
  20. 'trash': {'name': 'Trash', 'id': 3, 'docs': [2]},
  21. 'mine': [{'name': 'default', 'id': 2, 'docs': [3]}, {'name': 'web', 'id': 3, 'docs': [3]}],
  22. 'notmine': [{'name': 'example', 'id': 20, 'docs': [10]}, {'name': 'ex2', 'id': 30, 'docs': [10, 11]}]
  23. };
  24. var DOCUMENTS_DEFAULTS = {
  25. '1': {
  26. 'id': 1,
  27. 'name': 'my query history', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
  28. 'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
  29. },
  30. '2': {
  31. 'id': 2,
  32. 'name': 'my query 2 trashed', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
  33. 'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
  34. },
  35. '3': {
  36. 'id': 3,
  37. 'name': 'my query 3 tagged twice', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
  38. 'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
  39. },
  40. '10': {
  41. 'id': 10,
  42. 'name': 'my query 3 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
  43. 'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
  44. },
  45. '11': {
  46. 'id': 11,
  47. 'name': 'my query 4 shared', 'description': '', 'url': '/beeswax/execute/design/83', 'icon': '/beeswax/static/art/icon_beeswax_24.png',
  48. 'lastModified': '03/11/14 16:06:49', 'owner': 'admin', 'lastModifiedInMillis': 1394579209.0, 'isMine': true
  49. }
  50. };
  51. self.tags = ko.mapping.fromJS(TAGS_DEFAULTS);
  52. self.documents = ko.observableArray([]);
  53. self.editTagsToCreate = ko.observableArray([]);
  54. self.editTagsToDelete = ko.observableArray([]);
  55. self.trash = ko.computed(function() {
  56. return self.tags.trash;
  57. });
  58. self.history = ko.computed(function() {
  59. return self.tags.history;
  60. });
  61. self.myTags = ko.computed(function() {
  62. return self.tags.mine();
  63. });
  64. self.sharedTags = ko.computed(function() {
  65. return self.tags.notmine();
  66. });
  67. self.filterDocs = function(tag) {
  68. self.documents.removeAll();
  69. $.each(DOCUMENTS_DEFAULTS, function(id, doc) {
  70. if (tag.docs().indexOf(parseInt(id)) != -1) { // Beware, keys are strings in js
  71. self.documents.push(doc); // pushall?
  72. }
  73. })
  74. }
  75. self.createTag = function(tag_json) {
  76. var mapped_tag = ko.mapping.fromJS({'name': 'default2', 'id': 50, 'docs': [3]}); // todo
  77. self.tags.mine.push(mapped_tag);
  78. }
  79. }