瀏覽代碼

W2.5: add insert editing user in the DB.

Frederic G. MARAND 8 年之前
父節點
當前提交
c27798e18e
共有 5 個文件被更改,包括 114 次插入69 次删除
  1. 2 1
      .eslintrc.js
  2. 0 1
      .meteor/packages
  3. 0 1
      .meteor/versions
  4. 78 64
      client/accounts.js
  5. 34 2
      textcircle.js

+ 2 - 1
.eslintrc.js

@@ -23,7 +23,8 @@ module.exports = {
     "check": true,
 
     // Project-specific.
-    "Documents": true
+    "Documents": true,
+    "EditingUsers": true
   },
 
   "plugins": ["react"],

+ 0 - 1
.meteor/packages

@@ -5,7 +5,6 @@
 # but you can also edit it by hand.
 
 autopublish
-insecure
 mizzao:sharejs-codemirror
 twbs:bootstrap
 standard-minifiers

+ 0 - 1
.meteor/versions

@@ -36,7 +36,6 @@ htmljs@1.0.5
 http@1.1.1
 ian:accounts-ui-bootstrap-3@1.2.89
 id-map@1.0.4
-insecure@1.0.4
 jquery@1.11.4
 launch-screen@1.0.4
 livedata@1.0.15

+ 78 - 64
client/accounts.js

@@ -1,72 +1,86 @@
 // configure the special accounts user interface
 // by setting up some extra fields and specifying constraints
-// see:https://github.com/ianmartorell/meteor-accounts-ui-bootstrap-3/    
+// see:https://github.com/ianmartorell/meteor-accounts-ui-bootstrap-3/
 Accounts.ui.config({
   requestPermissions: {},
-  extraSignupFields: [{
-    fieldName: "first-name",
-    fieldLabel: "First name",
-    inputType: "text",
-    visible: true,
-    validate: function (value, errorFunction) {
-      if (!value) {
-        errorFunction("Please write your first name");
-        return false;
-          } else {
-        return true;
+  extraSignupFields: [
+    {
+      fieldName: "first-name",
+      fieldLabel: "First name",
+      inputType: "text",
+      visible: true,
+      validate: function (value, errorFunction) {
+        if (!value) {
+          errorFunction("Please write your first name");
+          return false;
+        }
+        else {
+          return true;
+        }
       }
-    }
-  }, {
-    fieldName: "last-name",
-    fieldLabel: "Last name",
-    inputType: "text",
-    visible: true,
-  }, {
-        fieldName: 'gender',
-        showFieldLabel: false,      // If true, fieldLabel will be shown before radio group
-        fieldLabel: 'Gender',
-        inputType: 'radio',
-        radioLayout: 'vertical',    // It can be 'inline' or 'vertical'
-        data: [{                    // Array of radio options, all properties are required
-            id: 1,                  // id suffix of the radio element
-            label: 'Male',          // label for the radio element
-            value: 'm'              // value of the radio element, this will be saved.
-          }, {
-            id: 2,
-            label: 'Female',
-            value: 'f',
-            checked: 'checked'
-        }],
-        visible: true
-    }, {
-        fieldName: 'country',
-        fieldLabel: 'Country',
-        inputType: 'select',
-        showFieldLabel: true,
-        empty: 'Please select your country of residence',
-        data: [{
-            id: 1,
-            label: 'United States',
-            value: 'us'
-          }, {
-            id: 2,
-            label: 'Spain',
-            value: 'es',
-        }],
-        visible: true
-    }, {
-    fieldName: "terms",
-    fieldLabel: "I accept the terms and conditions <a href=\"\">Some outrageous terms</a>",
-    inputType: "checkbox",
-    visible: true,
-        saveToProfile: false,
-    validate: function (value, errorFunction) {
-      if (value) {
-        return true;
-            } else {
-                errorFunction('You must accept the terms and conditions.');
-        return false;
+    },
+    {
+      fieldName: "last-name",
+      fieldLabel: "Last name",
+      inputType: "text",
+      visible: true
+    },
+    {
+      fieldName: "gender",
+      showFieldLabel: false,      // If true, fieldLabel will be shown before radio group
+      fieldLabel: "Gender",
+      inputType: "radio",
+      radioLayout: "vertical",    // It can be "inline" or "vertical"
+      data: [
+        {                    // Array of radio options, all properties are required
+          id: 1,                  // id suffix of the radio element
+          label: "Male",          // label for the radio element
+          value: "m"              // value of the radio element, this will be saved.
+        },
+        {
+          id: 2,
+          label: "Female",
+          value: "f",
+          checked: "checked"
+        }
+      ],
+      visible: true
+    },
+    {
+      fieldName: "country",
+      fieldLabel: "Country",
+      inputType: "select",
+      showFieldLabel: true,
+      empty: "Please select your country of residence",
+      data: [
+        {
+          id: 1,
+          label: "United States",
+          value: "us"
+        },
+        {
+          id: 2,
+          label: "Spain",
+          value: "es"
+        }
+      ],
+      visible: true
+    },
+    {
+      fieldName: "terms",
+      fieldLabel: "I accept the terms and conditions <a href=\"\">Some outrageous terms</a>",
+      inputType: "checkbox",
+      visible: true,
+      saveToProfile: false,
+      validate: function (value, errorFunction) {
+        if (value) {
+          return true;
+        }
+        else {
+          errorFunction("You must accept the terms and conditions.");
+          return false;
+        }
       }
     }
-  }]
+  ]
 });

+ 34 - 2
textcircle.js

@@ -1,6 +1,7 @@
 // This collection stores all the documents.
 // Note: not Documents, but this.Documents, because of the editing package (?)
 this.Documents = new Mongo.Collection("documents");
+EditingUsers = new Mongo.Collection("editingUsers");
 
 if (Meteor.isClient) {
   Template.editor.helpers({
@@ -12,9 +13,12 @@ if (Meteor.isClient) {
     // Configure the CodeMirror editor.
     config: function () {
       return function (editor) {
-        editor.on("change", function (cm_editor, info) {
+        editor.setOption("lineNumbers", true);
+        editor.setOption("mode", "html");
+        editor.on("change", function (cmEditor, info) {
           let $preview = $("#viewer_iframe");
-          $preview.contents().find("html").html(cm_editor.getValue());
+          $preview.contents().find("html").html(cmEditor.getValue());
+          Meteor.call("addEditingUser");
         });
       };
     },
@@ -30,3 +34,31 @@ if (Meteor.isServer) {
     }
   });
 }
+
+Meteor.methods({
+  addEditingUser: function () {
+    var doc, user, eUsers;
+    doc = Documents.findOne();
+    if (!doc) {
+      // No doc: give up.
+      return;
+    }
+    if (!this.userId) {
+      // No logged-in user: give up.
+      return;
+    }
+    // Now I have a doc and possibly a user.
+    user = Meteor.user().profile;
+    eUsers = EditingUsers.findOne({ docId: doc._id });
+    // No editing users have been stored yet.
+    if (!eUsers) {
+      eUsers = {
+        docId: doc._id,
+        users: {}
+      };
+    }
+    user.lastEdit = new Date();
+    eUsers.users[this.userId] = user;
+    EditingUsers.upsert({ _id: eUsers._id }, eUsers);
+  }
+});