d3k4y:meteor-autoprofile

v0.1.4Published 7 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Meteor Autoprofile

Disclaimer

!WIP, the current version is 0.1.4!

Features

  • Generate profile pages based on SimplSchema model definitions
  • Configure the generated profile via a simple configuration object

Installation

$ meteor add d3k4y:meteor-autoprofile

There are some optional dependencies that you could install to extend the functionality (at least one of them is required to enable editing):

  • aldeed:autoform
  • d3k4y:autoform-modals
  • babrahams:editable-text

Usage

Call the autoProfile template in one of your own templates:

$ {{> autoProfile options=getProfileOptions myContext=getContext}}

Create a 'profileOptions' helper to configure your profile:

1Template.myTemplate.helpers({
2    getProfileOptions() {
3        return {
4            collection: Meteor.users,
5            collectionName: 'Meteor.users',
6            method: 'myServerMethodToUpdateUserProfile',
7            rows: [{
8                cols: [
9                    {
10                        class: 'col-sm-6',
11                        panels: [
12                            {
13                                highlighted: true,
14                                view: 'list',
15                                titleField: {
16                                    group: [
17                                        {id: 'profile.salutation'},
18                                        {id: 'profile.name'},
19                                        {id: 'profile.surename'}
20                                    ]
21                                },
22                                fields: [
23                                    {id: 'username', editable: false},
24                                    {id: 'createdAt', editable: false}
25                                ]
26                            }
27                        ]
28                    }, {
29                        class: 'col-sm-3',
30                        panels: [
31                            {
32                                icon: 'link',
33                                view: 'list',
34                                field: {
35                                    id: 'profile.adresses',
36                                    titleField: {id: 'profile.adresses.$.kind'},
37                                    subfields: [
38                                        {id: 'profile.adresses.$.street'},
39                                        {id: 'profile.adresses.$.city'},
40                                        {id: 'profile.adresses.$.plz'},
41                                        {id: 'profile.adresses.$.country'}
42                                    ]
43                                }
44                            },
45        
46                        ]
47                    }, {
48                        class: 'col-sm-3',
49                        panels: [
50                            {
51                                icon: 'link',
52                                view: 'list',
53                                listContent: true,
54                                field: {
55                                    id: 'emails',
56                                    editable: false,
57                                    render: 'inplace', // default: 'sublist'
58                                    titleField: {id: 'emails.$.address'},
59                                    subfields: [
60                                        {id: 'emails.$.verified'}
61                                    ]
62                                }
63                            }
64                        ]
65                    }
66                ]
67            }]
68        };
69    }
70});

A SimplSchema definition for the related collection is required, e.g.:

1Meteor.users.attachSchema(new SimpleSchema({
2    _id: {
3      type: String,
4      max: 20,
5      optional: true,
6      autoform: {
7          afFieldInput: {
8              type: 'hidden',
9          },
10          afFormGroup: {
11              label: false
12          }
13      }
14    },
15    username: {
16      type: String,
17      label: "Benutzername",
18      optional: true
19    },
20    emails: {
21      type: Array,
22      label: "E-Mail Adressen",
23      optional: true
24    },
25    "emails.$": {
26      label: "E-Mail Adresse",
27      type: Object,
28      optional: true
29    },
30    "emails.$.address": {
31      label: "E-Mail Adresse",
32      type: String,
33      regEx: SimpleSchema.RegEx.Email,
34      optional: true
35    },
36    "emails.$.verified": {
37      label: "E-Mail Adresse bestätigt",
38      type: Boolean
39    },
40    createdAt: {
41      type: Date,
42      denyUpdate: true,
43      label: "Erstellt am",
44      autoValue() {
45          if (this.isInsert) {
46              return new Date();
47          } else if (this.isUpsert) {
48              return {$setOnInsert: new Date()};
49          } else if (this.isUpdate) {
50          } else {
51              this.unset();
52          }
53          return undefined;
54      },
55      autoform: {
56          omit: true
57      }
58    },
59    profile: {
60      type: new SimpleSchema({
61          salutation: {
62            type: String,
63            label: "Salutation",
64            allowedValues: ['Herr', 'Frau'],
65            optional: true,
66            max: 70
67          },
68          name: {
69            type: String,
70            label: "Name",
71            optional: true,
72            max: 70
73          },
74          surename: {
75            type: String,
76            label: "Surename",
77            optional: true,
78            max: 70
79          },
80          adresses: {
81            type: Array,
82            label: "Adressen",
83            optional: true
84          },
85          "adresses.$": {
86            type: Object,
87            label: "Adress"
88          },
89          "adresses.$.street": {
90            type: String,
91            label: "Street",
92            min: 0,
93            max: 70
94          },
95          "adresses.$.plz": {
96            type: String,
97            label: "Postal Code",
98            max: 20
99          },
100          "adresses.$.city": {
101            type: String,
102            label: "City",
103            max: 70
104          },
105          "adresses.$.state": {
106            type: String,
107            label: "State",
108            max: 70
109          },
110          "adresses.$.country": {
111            type: String,
112            label: "Country"
113          },
114          "adresses.$.kind": {
115            type: String,
116            label: "Adress Type",
117            allowedValues: ['business', 'private', 'both'],
118            autoform: {
119                options: [
120                    {label: "Business", value: "business"},
121                    {label: "Private", value: "private"},
122                    {label: "Both", value: "both"}
123                ]
124            }
125          },            
126      }),
127      label: "User Profile",
128      optional: true
129    },
130    services: {
131      type: Object,
132      optional: true,
133      blackbox: true,
134      autoform: {
135          omit: true
136      }
137    },
138    roles: {
139      type: Object,
140      blackbox: true,
141      optional: true
142    },
143    heartbeat: {
144      type: Date,
145      optional: true,
146      autoform: {
147          omit: true
148      }
149    }
150}));