Browse Source

fix a few server side things, navigate to stuff after creation

Benoît Hubert 8 years ago
parent
commit
067b2a6e24
4 changed files with 9 additions and 5 deletions
  1. 2 0
      js/ws-forms.js
  2. 4 4
      js/ws-menu.js
  3. 1 0
      lib/ExampleStore.js
  4. 2 1
      sandboxApp.js

+ 2 - 0
js/ws-forms.js

@@ -140,6 +140,7 @@ function checkPropsExist(obj, props) {
     onAddSuccess: function(repo) {
       console.log('****** onAddSuccess repo', repo);
       _ws.notify('success', 'Collection créée: ' + repo.title);
+      _ws.navigateTo('/' + repo.path);
     },
     onAddError: function(err) {
      _ws.notify('error', 'Impossible de créer la collection: ' + err.message); 
@@ -153,6 +154,7 @@ function checkPropsExist(obj, props) {
     onAddSuccess: function(example) {
       console.log('****** onAddSuccess example', example);
       _ws.notify('success', 'Exemple crée: ' + example.title);
+      _ws.navigateTo('/' + _ws.repo.path + '/' + example.slug);
     },
     onAddError: function(err) {
      _ws.notify('error', "Impossible de créer l'exemple: " + err.message); 

+ 4 - 4
js/ws-menu.js

@@ -50,7 +50,7 @@
     /**
      * Handle navigation
      */
-     function navigateTo(path) {
+    _ws.navigateTo = function(path) {
       $('#server-alert').remove();
       history.pushState({}, 'New path', path);
       prevNavState = navState;
@@ -109,7 +109,7 @@
       $link.animate({
         backgroundColor: originalColor,
       }, 70);
-      navigateTo($link.prop('href'));
+      _ws.navigateTo($link.prop('href'));
     }
 
 
@@ -139,7 +139,7 @@
     $('#nav-back-home').click(function(e) {
       e.preventDefault();
       $mainMenu.removeClass('in');
-      navigateTo('/');
+      _ws.navigateTo('/');
     });
 
 
@@ -164,7 +164,7 @@
     //     var $exMenuItem = $('<li><a href="/' + repoSlug + '/' + example.slug + '">' + example.title + '</a></li>')
     //     .appendTo( $('#cat-' + example.category) );
     //     notify('success', "Exemple créé !");
-    //     navigateTo('/'+ repoSlug + '/' + example.slug);
+    //     _ws.navigateTo('/'+ repoSlug + '/' + example.slug);
     //   })
     //   .catch(errText => notify('error', 'Erreur: ' + errText));
     // }

+ 1 - 0
lib/ExampleStore.js

@@ -47,6 +47,7 @@ ExampleStore.prototype.addRepository = function(repoPath, repoDescriptor) {
 
   // Add repo path to descriptor
   repoDescriptor.path = repoPath;
+  repoDescriptor.fullPath = this.rootPath + '/' + repoPath;
   
   return fs.mkdirAsync(fullPath)
   .then(() => fs.writeFileAsync(repoConfigFile, repoConfig))

+ 2 - 1
sandboxApp.js

@@ -169,7 +169,8 @@ app.post('/repos',
 
     // Prepare config
     var config = Object.assign({
-      title
+      title,
+      examples: []
     }, repoTmpl);
 
     exStore.addRepository(repoSlug, config)