@dhyasama/totem-models 6.11.8 → 6.11.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/Deal.js CHANGED
@@ -148,8 +148,8 @@ module.exports = function(mongoose, config) {
148
148
  })
149
149
  .populate('organization', 'name logoUrl website websiteAliases')
150
150
  .populate('messages')
151
- .populate('sources.person', 'name avatarUrl title')
152
- .populate('referrers.person', 'name avatarUrl title')
151
+ .populate('source.person', 'name avatarUrl title')
152
+ .populate('referrer.person', 'name avatarUrl title')
153
153
  .populate({
154
154
  path: 'documents',
155
155
  match: { customer: config.CUSTOMER_ID }
@@ -177,8 +177,8 @@ module.exports = function(mongoose, config) {
177
177
  .find(terms)
178
178
  .populate('organization', 'name description logoUrl website websiteAliases chairs')
179
179
  .populate('messages')
180
- .populate('sources.person', 'name avatarUrl title')
181
- .populate('referrers.person', 'name avatarUrl title')
180
+ .populate('source.person', 'name avatarUrl title')
181
+ .populate('referrer.person', 'name avatarUrl title')
182
182
  .populate({
183
183
  path: 'documents',
184
184
  match: { customer: customerId }
@@ -224,8 +224,8 @@ module.exports = function(mongoose, config) {
224
224
  })
225
225
  .populate('organization', 'name logoUrl website websiteAliases')
226
226
  .populate('messages')
227
- .populate('sources.person', 'name avatarUrl title')
228
- .populate('referrers.person', 'name avatarUrl title')
227
+ .populate('source.person', 'name avatarUrl title')
228
+ .populate('referrer.person', 'name avatarUrl title')
229
229
  .populate({
230
230
  path: 'documents',
231
231
  match: { customer: config.CUSTOMER_ID }
@@ -206,14 +206,84 @@ module.exports = function(mongoose, config) {
206
206
 
207
207
  active: { type: Boolean, default: false },
208
208
 
209
- stages: [{
209
+ statuses: [{
210
210
  name: { type: String, trim: true },
211
211
  order: { type: Number },
212
212
  active: { type: Boolean, default: true },
213
213
  color: { type: String, trim: true }
214
214
  }],
215
215
 
216
- fields: [{
216
+ standardFields: {
217
+
218
+ // Standard fields are always "on" in the system
219
+ // They can be configured in how they work on the deal list page
220
+ // order for standard fields only sets the order on the list page. their position is fixed on the org page deal section and edit form.
221
+ // order is co-mingled with order for custom fields
222
+ // colspan is for the number of columns the field should take up on the list page
223
+ // showOnFilter controls whether values are extracted and used in filtering options on list page
224
+ // showOnList controls if the field will be on deal list page
225
+
226
+ action: {
227
+ order: { type: Number, default: 99 },
228
+ colspan: { type: Number, default: 1 },
229
+ showOnFilter: { type: Boolean, default: true },
230
+ showOnList: { type: Boolean, default: true }
231
+ },
232
+
233
+ raise: {
234
+ order: { type: Number, default: 99 },
235
+ colspan: { type: Number, default: 1 },
236
+ showOnFilter: { type: Boolean, default: true },
237
+ showOnList: { type: Boolean, default: true }
238
+ },
239
+
240
+ valuation: {
241
+ order: { type: Number, default: 99 },
242
+ colspan: { type: Number, default: 1 },
243
+ showOnFilter: { type: Boolean, default: true },
244
+ showOnList: { type: Boolean, default: true }
245
+ },
246
+
247
+ sourcePerson: {
248
+ types: [ { type: String, trim: true } ],
249
+ order: { type: Number, default: 99 },
250
+ colspan: { type: Number, default: 1 },
251
+ showOnFilter: { type: Boolean, default: true },
252
+ showOnList: { type: Boolean, default: true }
253
+ },
254
+
255
+ sourceType: {
256
+ types: [ { type: String, trim: true } ],
257
+ order: { type: Number, default: 99 },
258
+ colspan: { type: Number, default: 1 },
259
+ showOnFilter: { type: Boolean, default: true },
260
+ showOnList: { type: Boolean, default: true }
261
+ },
262
+
263
+ referrerPerson: {
264
+ order: { type: Number, default: 99 },
265
+ colspan: { type: Number, default: 1 },
266
+ showOnFilter: { type: Boolean, default: true },
267
+ showOnList: { type: Boolean, default: true }
268
+ },
269
+
270
+ referrerType: {
271
+ order: { type: Number, default: 99 },
272
+ colspan: { type: Number, default: 1 },
273
+ showOnFilter: { type: Boolean, default: true },
274
+ showOnList: { type: Boolean, default: true }
275
+ },
276
+
277
+ chairs: {
278
+ order: { type: Number, default: 99 },
279
+ colspan: { type: Number, default: 1 },
280
+ showOnFilter: { type: Boolean, default: true },
281
+ showOnList: { type: Boolean, default: true }
282
+ }
283
+
284
+ },
285
+
286
+ customFields: [{
217
287
 
218
288
  // Data stored on deals will be accessed with this key
219
289
  // It must follow standard js variable naming rules
@@ -222,9 +292,6 @@ module.exports = function(mongoose, config) {
222
292
  // Changing it after data is in the system will make data on deal inaccessible
223
293
  key: { type: String, trim: true },
224
294
 
225
- // this sets whether the field is a custom field
226
- isStandard: false,
227
-
228
295
  // User friendly text, will be displayed
229
296
  label: { type: String, trim: true },
230
297
 
@@ -256,12 +323,13 @@ module.exports = function(mongoose, config) {
256
323
  // colspan is for the number of columns the field should take up on the list page
257
324
  colspan: { type: Number, default: 1 },
258
325
 
259
- // showOnList controls if the field will be on deal list page
260
- showOnList: { type: Boolean, default: true },
261
-
262
326
  // showOnFilter controls whether values are extracted and used in filtering options on list page
263
327
  showOnFilter: { type: Boolean, default: true },
264
328
 
329
+ // showOnList controls if the field will be on deal list page
330
+ // fields are always shown on org pages and in edit forms
331
+ showOnList: { type: Boolean, default: true }
332
+
265
333
  }
266
334
 
267
335
  }]
@@ -440,7 +508,7 @@ module.exports = function(mongoose, config) {
440
508
 
441
509
  });
442
510
 
443
- Organization.virtual('customer.deals.activeStages').get(function () {
511
+ Organization.virtual('customer.deals.activeStatuses').get(function () {
444
512
 
445
513
  var self = this;
446
514
 
@@ -450,12 +518,163 @@ module.exports = function(mongoose, config) {
450
518
  // Deals aren't on for customer
451
519
  else if (!self.customer.deals.active) return [];
452
520
 
453
- // Get active stage names and sort them
454
- var stages = _.filter(self.customer.deals.stages, function(s) { return s.active; });
455
- stages = _.sortBy(stages, 'order');
456
- stages = _.pluck(stages, 'name');
521
+ // Get active status names and sort them
522
+ var statuses = _.filter(self.customer.deals.statuses, function(s) { return s.active; });
523
+ statuses = _.sortBy(statuses, 'order');
524
+ statuses = _.pluck(statuses, 'name');
525
+
526
+ return statuses;
527
+
528
+ });
529
+
530
+ Organization.virtual('customer.deals.fields').get(function () {
531
+
532
+ // Combine standard fields and custom fields into a single list and sort by column order
533
+ // Fundraise is actually two fields, so multiply the order by ten to make room for the extra field
534
+
535
+ var self = this;
457
536
 
458
- return stages;
537
+ var standardFields = self.customer.deals.standardFields;
538
+
539
+ // Defaulting to off so it will be immediately apparent the customer hasn't been properly configured
540
+ standardFields = standardFields || {
541
+ fundraise: {
542
+ showOnList: false
543
+ },
544
+ sources: {
545
+ showOnList: false
546
+ },
547
+ referrers: {
548
+ showOnList: false
549
+ }
550
+ };
551
+
552
+ var customFields = self.customer.deals.customFields;
553
+ var result = [];
554
+
555
+ // Add standard fields
556
+ if (standardFields.action.showOnList) {
557
+ result.push({
558
+ name: 'Next Steps',
559
+ type: 'Text',
560
+ key: 'action',
561
+ isStandard: true,
562
+ order: standardFields.action.order * 10,
563
+ colspan: standardFields.action.colspan || 1,
564
+ showOnFilter: standardFields.action.showOnFilter === true ? true : false
565
+ });
566
+ }
567
+
568
+ if (standardFields.raise.showOnList) {
569
+ result.push({
570
+ name: 'Raise',
571
+ type: 'Money',
572
+ key: 'fundraise.amount',
573
+ isStandard: true,
574
+ order: standardFields.raise.order * 10,
575
+ colspan: standardFields.raise.colspan || 1,
576
+ showOnFilter: standardFields.raise.showOnFilter === true ? true : false
577
+ });
578
+ }
579
+
580
+ if(standardFields.valuation.showOnList) {
581
+ result.push({
582
+ name: 'Valuation',
583
+ type: 'Money',
584
+ key: 'fundraise.valuation',
585
+ isStandard: true,
586
+ order: standardFields.valuation.order * 10 + 1,
587
+ colspan: standardFields.valuation.colspan || 1,
588
+ showOnFilter: standardFields.valuation.showOnFilter === true ? true : false
589
+ });
590
+ }
591
+
592
+ if (standardFields.sourcePerson.showOnList) {
593
+ result.push({
594
+ name: 'Source Person',
595
+ type: 'Reference',
596
+ key: 'source.person',
597
+ isStandard: true,
598
+ order: standardFields.sourceName.order * 10,
599
+ colspan: standardFields.sourceName.colspan || 1,
600
+ showOnFilter: standardFields.sourceName.showOnFilter === true ? true : false
601
+ });
602
+ }
603
+
604
+ if (standardFields.sourceType.showOnList) {
605
+ result.push({
606
+ name: 'Source Type',
607
+ type: 'Single Select',
608
+ key: 'source.type',
609
+ isStandard: true,
610
+ order: standardFields.sourceType.order * 10,
611
+ colspan: standardFields.sourceType.colspan || 1,
612
+ showOnFilter: standardFields.sourceType.showOnFilter === true ? true : false
613
+ });
614
+ }
615
+
616
+ if (standardFields.referrerPerson.showOnList) {
617
+ result.push({
618
+ name: 'Referrer Person',
619
+ type: 'Reference',
620
+ key: 'referrer.person',
621
+ isStandard: true,
622
+ order: standardFields.referrerName.order * 10,
623
+ colspan: standardFields.referrerName.colspan || 1,
624
+ showOnFilter: standardFields.referrerName.showOnFilter === true ? true : false
625
+ });
626
+ }
627
+
628
+ if (standardFields.referrerType.showOnList) {
629
+ result.push({
630
+ name: 'Referrer Type',
631
+ type: 'Single Select',
632
+ key: 'referrer.type',
633
+ isStandard: true,
634
+ order: standardFields.referrerType.order * 10,
635
+ colspan: standardFields.referrerType.colspan || 1,
636
+ showOnFilter: standardFields.referrerType.showOnFilter === true ? true : false
637
+ });
638
+ }
639
+
640
+ if (standardFields.chairs.showOnList) {
641
+ result.push({
642
+ name: 'Leads',
643
+ type: 'Reference',
644
+ key: 'organization.chairs',
645
+ isStandard: true,
646
+ order: standardFields.chairs.order * 10,
647
+ colspan: standardFields.chairs.colspan || 1,
648
+ showOnFilter: standardFields.chairs.showOnFilter === true ? true : false
649
+ });
650
+ }
651
+
652
+ // Add custom fields
653
+ _.each(customFields, function(field) {
654
+ if (field.display.showOnList) {
655
+ result.push({
656
+ name: field.label,
657
+ type: field.type,
658
+ isStandard: false,
659
+ key: field.key,
660
+ options: field.options,
661
+ order: field.display.order * 10,
662
+ colspan: field.display.colspan || 1,
663
+ showOnFilter: field.display.showOnFilter === true ? true : false
664
+ });
665
+ }
666
+ });
667
+
668
+ // Sort the combined standard and custom fields
669
+ result = _.sortBy(result, function(item) { return item.order; });
670
+
671
+ // Now that we have all fields combined and ordered, make column order zero-indexed and gap-free
672
+ result = _.map(result, function(item, index) {
673
+ item.order = index;
674
+ return item;
675
+ });
676
+
677
+ return result;
459
678
 
460
679
  });
461
680
 
@@ -755,10 +974,10 @@ module.exports = function(mongoose, config) {
755
974
  if (err) return callback(err, null);
756
975
  else if (!org) return callback(new Error('Customer not found'), null);
757
976
 
758
- var stages = org.customer.deals.activeStatuses;
977
+ var statuses = org.customer.deals.activeStatuses;
759
978
 
760
- var match = _.find(stages, function(stage) {
761
- return stage == previous.deal.stage;
979
+ var match = _.find(statuses, function(status) {
980
+ return status == previous.deal.stage;
762
981
  });
763
982
 
764
983
  if (!match) return callback(new Error('This stage is not valid for this customer'), null);
@@ -1823,4 +2042,4 @@ module.exports = function(mongoose, config) {
1823
2042
 
1824
2043
  mongoose.model('Organization', Organization, 'organizations');
1825
2044
 
1826
- };
2045
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhyasama/totem-models",
3
- "version": "6.11.8",
3
+ "version": "6.11.10",
4
4
  "author": "Jason Reynolds",
5
5
  "license": "UNLICENSED",
6
6
  "description": "Models for Totem platform",