project-deployer.js 2.6 KB

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