GitLabFile.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Copyright (c) 2006-2017, JGraph Ltd
  3. * Copyright (c) 2006-2017, Gaudenz Alder
  4. */
  5. GitLabFile = function(ui, data, meta)
  6. {
  7. GitHubFile.call(this, ui, data, meta);
  8. this.peer = this.ui.gitLab;
  9. };
  10. //Extends mxEventSource
  11. mxUtils.extend(GitLabFile, GitHubFile);
  12. /**
  13. * Returns true if copy, export and print are not allowed for this file.
  14. */
  15. GitLabFile.prototype.getFileUrl = function()
  16. {
  17. return this.meta.html_url;
  18. };
  19. /**
  20. * Returns true if copy, export and print are not allowed for this file.
  21. */
  22. GitLabFile.prototype.getFolderUrl = function()
  23. {
  24. var url = this.getFileUrl();
  25. return url.substring(0, url.lastIndexOf('/'));
  26. };
  27. /**
  28. * Translates this point by the given vector.
  29. *
  30. * @param {number} dx X-coordinate of the translation.
  31. * @param {number} dy Y-coordinate of the translation.
  32. */
  33. GitLabFile.prototype.share = function()
  34. {
  35. this.ui.editor.graph.openLink(DRAWIO_GITLAB_URL + '/' +
  36. this.meta.org + '/' + encodeURIComponent(this.meta.repo) +
  37. '/-/project_members');
  38. };
  39. /**
  40. * Translates this point by the given vector.
  41. *
  42. * @param {number} dx X-coordinate of the translation.
  43. * @param {number} dy Y-coordinate of the translation.
  44. */
  45. GitLabFile.prototype.getId = function()
  46. {
  47. return this.meta.org + '/' +
  48. ((this.meta.repo != null) ? encodeURIComponent(this.meta.repo) + '/' +
  49. ((this.meta.ref != null) ? this.meta.ref +
  50. ((this.meta.path != null) ? '/' + this.meta.path : '') : '') : '');
  51. };
  52. /**
  53. * Translates this point by the given vector.
  54. *
  55. * @param {number} dx X-coordinate of the translation.
  56. * @param {number} dy Y-coordinate of the translation.
  57. */
  58. GitLabFile.prototype.getHash = function()
  59. {
  60. return encodeURIComponent('A' + this.getId());
  61. };
  62. /**
  63. * Adds the listener for automatically saving the diagram for local changes.
  64. */
  65. GitLabFile.prototype.isConflict = function(err)
  66. {
  67. return err != null && err.status == 400;
  68. };
  69. /**
  70. * Translates this point by the given vector.
  71. *
  72. * @param {number} dx X-coordinate of the translation.
  73. * @param {number} dy Y-coordinate of the translation.
  74. */
  75. GitLabFile.prototype.getMode = function()
  76. {
  77. return App.MODE_GITLAB;
  78. };
  79. /**
  80. * Adds all listeners.
  81. */
  82. GitLabFile.prototype.getDescriptorEtag = function(desc)
  83. {
  84. return desc.last_commit_id;
  85. };
  86. /**
  87. * Adds the listener for automatically saving the diagram for local changes.
  88. */
  89. GitLabFile.prototype.setDescriptorEtag = function(desc, etag)
  90. {
  91. desc.last_commit_id = etag;
  92. };