project-deployer.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. Projects = new Mongo.Collection('projects');
  2. ProjectService = {
  3. insert: function(label, git_url, public_url, commands, callback) {
  4. Projects.insert({
  5. label: label,
  6. git_url: git_url,
  7. public_url: public_url,
  8. commands: commands
  9. }, callback);
  10. },
  11. update: function(id, label, git_url, public_url ,commands) {
  12. Projects.update(
  13. id,
  14. { $set: {
  15. label: label,
  16. git_url: git_url,
  17. public_url: public_url,
  18. commands: commands
  19. }
  20. }
  21. );
  22. },
  23. delete: function(id) {
  24. Projects.remove(id);
  25. },
  26. get: function(id) {
  27. return Projects.findOne({_id: id});
  28. },
  29. list: function() {
  30. return Projects.find({}, {sort: {label: 1}});
  31. }
  32. };
  33. if (Meteor.isClient) {
  34. Meteor.subscribe('projects');
  35. Template.management.helpers({
  36. projects: function () {
  37. return ProjectService.list();
  38. }
  39. });
  40. Template.projectForm.onRendered(function() {
  41. new Clipboard('.btn.clipboard');
  42. });
  43. Template.projectForm.events({
  44. 'submit .new-project': function (event) {
  45. event.preventDefault();
  46. var form = event.target;
  47. if( form.id.value ) {
  48. Meteor.call('editProject',form.id.value, form.label.value, form.git_url.value, form.public_url.value, form.commands.value);
  49. form.id.value = '';
  50. } else {
  51. Meteor.call('addProject', form.label.value, form.git_url.value, form.public_url.value, form.commands.value);
  52. }
  53. Session.set('projectToEdit', undefined);
  54. form.label.value = '';
  55. form.git_url.value = '';
  56. form.public_url.value = '';
  57. form.commands.value = '';
  58. },
  59. 'click .cancel': function(event) {
  60. event.preventDefault();
  61. Session.set('projectToEdit', undefined);
  62. },
  63. 'click .trash': function(event) {
  64. event.preventDefault();
  65. Meteor.call('deleteProject', Session.get('projectToEdit')._id);
  66. Session.set('projectToEdit', undefined);
  67. }
  68. });
  69. Template.projectForm.helpers({
  70. project: function() {
  71. return Session.get('projectToEdit');
  72. },
  73. editionMode: function() {
  74. return Session.get('projectToEdit') ? '' : 'hidden';
  75. },
  76. deployLink: function() {
  77. return Meteor.absoluteUrl('deploy?token=XXXX&project_id=' + Session.get('projectToEdit')._id);
  78. }
  79. });
  80. Template.project.events({
  81. 'click .edit': function(event) {
  82. event.preventDefault();
  83. return Meteor.call('getProject', this._id, function(error, result) {
  84. Session.set('projectToEdit', result);
  85. });
  86. },
  87. });
  88. }
  89. if (Meteor.isServer) {
  90. Meteor.publish('projects', function() {
  91. return Projects.find({});
  92. });
  93. }
  94. Meteor.methods({
  95. listProjects: function() {
  96. return ProjectService.list();
  97. },
  98. getProject: function(id) {
  99. return ProjectService.get(id);
  100. },
  101. addProject: function(label, git_url, public_url ,commands) {
  102. ProjectService.insert(label, git_url, public_url ,commands);
  103. },
  104. editProject: function(id, label, git_url, public_url ,commands) {
  105. ProjectService.update(id, label, git_url, public_url ,commands);
  106. },
  107. deleteProject: function(id) {
  108. ProjectService.delete(id);
  109. }
  110. });