hdfs.ko.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. var Assist = function (vm, assist) {
  17. var self = this;
  18. self.path = ko.observable('/tmp');
  19. self.files = ko.observableArray();
  20. self.acls = ko.observableArray();
  21. self.owner = ko.observable('');
  22. self.group = ko.observable('');
  23. self.changed = ko.observable(true); // mocking to true
  24. self.fetchPath = function () {
  25. $.getJSON('/filebrowser/view' + self.path() + "?pagesize=15&format=json", function (data) { // Will create a cleaner API by calling directly directly webhdfs#LISTDIR?
  26. self.files.removeAll();
  27. $.each(data.files, function(index, item) {
  28. self.files.push(item.path);
  29. });
  30. self.getAcls();
  31. }).fail(function (xhr, textStatus, errorThrown) {
  32. $(document).trigger("error", xhr.responseText);
  33. });
  34. };
  35. self.getAcls = function () {
  36. $.getJSON('/security/api/get_acls', {
  37. 'path': self.path()
  38. }, function (data) {
  39. self.acls.removeAll();
  40. $.each(data.entries, function(index, item) {
  41. self.acls.push(item);
  42. });
  43. self.acls.push("group::r-x"); // mocking
  44. self.acls.push("group:execs:r--"); // mocking
  45. self.owner(data.owner);
  46. self.group(data.group);
  47. }).fail(function (xhr, textStatus, errorThrown) {
  48. $(document).trigger("error", xhr.responseText);
  49. });
  50. };
  51. }
  52. var HdfsViewModel = function (context_json) {
  53. var self = this;
  54. // Models
  55. self.assist = new Assist(self, context_json.assist);
  56. self.assist.fetchPath();
  57. function logGA(page) {
  58. if (typeof trackOnGA == 'function') {
  59. trackOnGA('security/hdfs' + page);
  60. }
  61. }
  62. };