Quellcode durchsuchen

Commit 9-5-1: Created basic errors package and linked it in.

Frederic G. MARAND vor 9 Jahren
Ursprung
Commit
1c0bc01ba5

+ 1 - 0
.meteor/packages

@@ -12,3 +12,4 @@ sacha:spin
 ian:accounts-ui-bootstrap-3
 accounts-password
 audit-argument-checks
+fgm:errors

+ 2 - 0
.meteor/versions

@@ -15,6 +15,7 @@ deps@1.0.7
 ejson@1.0.6
 email@1.0.6
 fastclick@1.0.3
+fgm:errors@0.0.1
 geojson-utils@1.0.3
 html-tools@1.0.4
 htmljs@1.0.4
@@ -41,6 +42,7 @@ minifiers@1.1.5
 minimongo@1.0.8
 mobile-status-bar@1.0.3
 mongo@1.1.0
+mongo-livedata@1.0.8
 npm-bcrypt@0.7.8_2
 observe-sequence@1.0.6
 ordered-dict@1.0.3

+ 0 - 16
client/helpers/errors.js

@@ -1,16 +0,0 @@
-/**
- * @file
- *
- *
- * User: marand
- * Date: 03/09/15
- * Time: 16:46
- */
-
-// Local client-only collection.
-Errors = new Mongo.Collection(null);
-
-// Global
-throwError = function(message) {
-  Errors.insert({ message: message });
-};

+ 1 - 1
client/templates/application/layout.html

@@ -1,7 +1,7 @@
 <template name="layout">
   <div class="container">
     {{> header }}
-    {{> errors }}
+    {{> meteorErrors }}
     <div id="main">
       {{! IronRouter magic }}
       {{> yield }}

+ 0 - 22
client/templates/includes/errors.js

@@ -1,22 +0,0 @@
-/**
- * @file
- *
- *
- * User: marand
- * Date: 03/09/15
- * Time: 17:22
- */
-
-Template.errors.helpers({
-  errors: function () {
-    return Errors.find();
-  }
-});
-
-Template.error.onRendered(function () {
-  var error = this.data;
-  Meteor._debug(this.data);
-  Meteor.setTimeout(function () {
-    Errors.remove(error._id);
-  }, 3000);
-});

+ 1 - 1
client/templates/posts/post_edit.js

@@ -27,7 +27,7 @@ Template.postEdit.events({
     Posts.update(currentPostId, { $set: postProperties }, function (error) {
       // Display the error to the user and abort.
       if (error) {
-        return throwError(error.reason);
+        Errors.throw(error.reason);
       }
       else {
         Router.go('postPage', { _id: currentPostId });

+ 2 - 2
client/templates/posts/post_submit.js

@@ -26,10 +26,10 @@ Template.postSubmit.events({
     Meteor.call('postInsert', post, function (error, result) {
       // Display the error to the user and abort.
       if (error) {
-        return throwError(error.reason);
+        Errors.throw(error.reason);
       }
       if (result.postExists) {
-        throwError("This link has already been posted");
+        Errors.throw("This link has already been posted");
       }
 
       Router.go('postPage', { _id: result._id });

+ 1 - 0
packages/.gitignore

@@ -0,0 +1 @@
+.build*

+ 5 - 0
packages/fgm:errors/errors-tests.js

@@ -0,0 +1,5 @@
+// Write your tests here!
+// Here is an example.
+Tinytest.add('example', function (test) {
+  test.equal(true, true);
+});

+ 19 - 0
packages/fgm:errors/errors.js

@@ -0,0 +1,19 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 03/09/15
+ * Time: 16:46
+ */
+
+// Local client-only collection.
+Errors = {
+  collection: new Mongo.Collection(null),
+
+  throw : function(message) {
+    Errors.collection.insert({ message: message });
+  },
+
+  delay: 3000,
+};

+ 3 - 3
client/templates/includes/errors.html → packages/fgm:errors/errors_list.html

@@ -1,12 +1,12 @@
-<template name="errors">
+<template name="meteorErrors">
   <div class="errors">
     {{#each errors}}
-      {{> error }}
+      {{> meteorError }}
     {{/each}}
   </div>
 </template>
 
-<template name="error">
+<template name="meteorError">
   <div class="alert alert-danger" role="alert">
     <button type="button" class="close" data-dismiss="alert">&times;</button>
     {{ message }}

+ 21 - 0
packages/fgm:errors/errors_list.js

@@ -0,0 +1,21 @@
+/**
+ * @file
+ *
+ *
+ * User: marand
+ * Date: 03/09/15
+ * Time: 20:51
+ */
+
+Template.meteorErrors.helpers({
+  errors: function () {
+    return Errors.collection.find();
+  }
+});
+
+Template.meteorError.rendered = function () {
+  var error = this.data;
+  Meteor.setTimeout(function () {
+    Errors.collection.remove(error._id);
+  }, Errors.delay);
+};

+ 32 - 0
packages/fgm:errors/package.js

@@ -0,0 +1,32 @@
+Package.describe({
+  name: 'fgm:errors',
+  version: '0.0.1',
+
+  // Brief, one-line summary of the package.
+  summary: 'A pattern to display application errors to the user',
+
+  // URL to the Git repository containing the source code for this package.
+  // git: '',
+
+  // By default, Meteor will default to using README.md for documentation.
+  // To avoid submitting documentation, set this field to null.
+  // documentation: 'README.md'
+});
+
+Package.onUse(function(api) {
+  var where = 'client';
+
+  api.versionsFrom('1.1.0.3');
+  api.use(['minimongo', 'mongo-livedata', 'templating'], where);
+  api.addFiles(['errors.js', 'errors_list.html', 'errors_list.js'], where);
+
+  if (api.export) {
+    api.export('Errors');
+  }
+});
+
+Package.onTest(function(api) {
+  api.use('tinytest');
+  api.use('fgm:errors');
+  api.addFiles('errors-tests.js');
+});