| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- Projects = new Mongo.Collection('projects');
- if (Meteor.isClient) {
- Meteor.subscribe('projects');
- Template.management.helpers({
- projects: function () {
- return Projects.find({}, {sort: {label: 1}});
- }
- });
- Template.projectForm.onRendered(function() {
- new Clipboard('.btn.clipboard');
- });
-
- Template.projectForm.events({
- 'submit .new-project': function (event) {
- event.preventDefault();
- var form = event.target;
- console.log('handled', form.id.value);
- if( form.id.value ) {
- Meteor.call('editProject',form.id.value, form.label.value, form.git_url.value, form.public_url.value, form.commands.value);
- form.id.value = '';
- } else {
- Meteor.call('addProject', form.label.value, form.git_url.value, form.public_url.value, form.commands.value);
- }
-
- Session.set('projectToEdit', undefined);
- form.label.value = '';
- form.git_url.value = '';
- form.public_url.value = '';
- form.commands.value = '';
- },
-
- 'click .cancel': function(event) {
- event.preventDefault();
-
- Session.set('projectToEdit', undefined);
- },
-
- 'click .trash': function(event) {
- event.preventDefault();
-
- Meteor.call('deleteProject', Session.get('projectToEdit')._id);
- Session.set('projectToEdit', undefined);
- }
- });
-
- Template.projectForm.helpers({
- project: function() {
- return Session.get('projectToEdit');
- },
-
- editionMode: function() {
- return Session.get('projectToEdit') ? '' : 'hidden';
- },
-
- deployLink: function() {
- return Meteor.absoluteUrl('deploy?token=XXXX&project_id=' + Session.get('projectToEdit')._id);
- }
- });
-
- Template.project.events({
- 'click .edit': function(event) {
- event.preventDefault();
- return Meteor.call('getProject', this._id, function(error, result) {
- Session.set('projectToEdit', result);
- });
- },
- });
-
- }
- if (Meteor.isServer) {
- Meteor.publish('projects', function() {
- return Projects.find({});
- });
- }
- Meteor.methods({
- listProjects: function() {
- return Projects.find({}, {sort: {label: 1}});
- },
-
- getProject: function(id) {
- return Projects.findOne({_id: id});
- },
-
- addProject: function(label, git_url, public_url ,commands) {
- console.log('addProjects', arguments);
- Projects.insert({
- label: label,
- git_url: git_url,
- public_url: public_url,
- commands: commands
- });
- },
-
- editProject: function(id, label, git_url, public_url ,commands) {
- console.log('editProjects', arguments);
- Projects.update(
- id,
- { $set: {
- label: label,
- git_url: git_url,
- public_url: public_url,
- commands: commands
- }
- }
- );
- },
-
- deleteProject: function(id) {
- Projects.remove(id);
- }
- });
|