@dhyasama/totem-models 6.2.0 → 6.3.0
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/.npmignore +14 -0
- package/lib/Organization.js +135 -5
- package/package-lock.json +1829 -0
- package/package.json +1 -1
- package/test/Organization.js +64 -0
package/.npmignore
ADDED
package/lib/Organization.js
CHANGED
|
@@ -213,6 +213,50 @@ module.exports = function(mongoose, config) {
|
|
|
213
213
|
color: { type: String, trim: true }
|
|
214
214
|
}],
|
|
215
215
|
|
|
216
|
+
standardFields: {
|
|
217
|
+
|
|
218
|
+
// active set to false will keep the field out of system for customer, i.e., off list page, org page deal section and deal edit form
|
|
219
|
+
// showOnList controls if the field will be on deal list page
|
|
220
|
+
// if a field is active, it will show up on the org page deal section and deal edit form. there is no way to hide it in those places.
|
|
221
|
+
// 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.
|
|
222
|
+
// order is co-mingled with order for custom fields
|
|
223
|
+
// filter controls whether values are extracted and used in filtering options on list page
|
|
224
|
+
// colSpan is for table on list page
|
|
225
|
+
|
|
226
|
+
fundraise: {
|
|
227
|
+
active: { type: Boolean, default: true },
|
|
228
|
+
showOnList: { type: Boolean, default: true },
|
|
229
|
+
order: { type: Number, default: 1 },
|
|
230
|
+
filter: { type: Boolean, default: false },
|
|
231
|
+
colSpan: { type: Number, default: 1 }
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
sources: {
|
|
235
|
+
active: { type: Boolean, default: true },
|
|
236
|
+
showOnList: { type: Boolean, default: false },
|
|
237
|
+
order: { type: Number, default: 99 },
|
|
238
|
+
filter: { type: Boolean, default: false },
|
|
239
|
+
colSpan: { type: Number, default: 1 }
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
referrers: {
|
|
243
|
+
active: { type: Boolean, default: true },
|
|
244
|
+
showOnList: { type: Boolean, default: false },
|
|
245
|
+
order: { type: Number, default: 99 },
|
|
246
|
+
filter: { type: Boolean, default: false },
|
|
247
|
+
colSpan: { type: Number, default: 1 }
|
|
248
|
+
},
|
|
249
|
+
|
|
250
|
+
resources: {
|
|
251
|
+
active: { type: Boolean, default: true },
|
|
252
|
+
showOnList: { type: Boolean, default: false },
|
|
253
|
+
order: { type: Number, default: 99 },
|
|
254
|
+
filter: { type: Boolean, default: false },
|
|
255
|
+
colSpan: { type: Number, default: 1 }
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
},
|
|
259
|
+
|
|
216
260
|
customFields: [{
|
|
217
261
|
|
|
218
262
|
// Data stored on deals will be accessed with this key
|
|
@@ -239,21 +283,21 @@ module.exports = function(mongoose, config) {
|
|
|
239
283
|
value: { type: String, trim: true, required: true },
|
|
240
284
|
|
|
241
285
|
// This is used to validate and aggregate answers for polls
|
|
242
|
-
type: { type: String, enum: ['String', 'Number', 'Boolean'] }
|
|
286
|
+
type: { type: String, enum: ['String', 'Number', 'Boolean'], required: true }
|
|
243
287
|
|
|
244
288
|
}],
|
|
245
289
|
|
|
246
290
|
// For controlling display on web pages
|
|
247
291
|
display: {
|
|
248
292
|
|
|
249
|
-
// Sets the order to render fields
|
|
293
|
+
// Sets the order to render fields on list, org page deal section and deal edit form
|
|
250
294
|
order: { type: Number },
|
|
251
295
|
|
|
252
296
|
// Sets the number of columns for this property to span on the deals list
|
|
253
|
-
colspan:
|
|
297
|
+
colspan: { type: Number, default: 1 },
|
|
254
298
|
|
|
255
|
-
// Optionally include as an option on the deal
|
|
256
|
-
showOnFilter: {},
|
|
299
|
+
// Optionally include as an option on the deal
|
|
300
|
+
showOnFilter: { type: Boolean, default: true },
|
|
257
301
|
|
|
258
302
|
// Optionally show or hide fields on deals list
|
|
259
303
|
// Fields are always shown on org pages and in edit forms
|
|
@@ -456,6 +500,92 @@ module.exports = function(mongoose, config) {
|
|
|
456
500
|
|
|
457
501
|
});
|
|
458
502
|
|
|
503
|
+
Organization.virtual('customer.deals.columns').get(function () {
|
|
504
|
+
|
|
505
|
+
// Combine ever-present fields, standard fields and custom fields into a single list and sort by column order
|
|
506
|
+
// Fundraise is actually two fields, so multiply the order by ten to make room for the extra field
|
|
507
|
+
// Returns tuples of name/order
|
|
508
|
+
|
|
509
|
+
var self = this;
|
|
510
|
+
|
|
511
|
+
var standardFields = self.customer.deals.standardFields;
|
|
512
|
+
|
|
513
|
+
// Defaulting to off so it will be immediately apparent the customer hasn't been properly configured
|
|
514
|
+
standardFields = standardFields || {
|
|
515
|
+
fundraise: {
|
|
516
|
+
active: false,
|
|
517
|
+
showOnList: false
|
|
518
|
+
},
|
|
519
|
+
sources: {
|
|
520
|
+
active: false,
|
|
521
|
+
showOnList: false
|
|
522
|
+
},
|
|
523
|
+
referrers: {
|
|
524
|
+
active: false,
|
|
525
|
+
showOnList: false
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
var customFields = self.customer.deals.customFields;
|
|
530
|
+
var result = [];
|
|
531
|
+
|
|
532
|
+
// Add the standard fields that are active
|
|
533
|
+
if (standardFields.fundraise.active && standardFields.fundraise.showOnList) {
|
|
534
|
+
result.push({
|
|
535
|
+
name: 'Fundraise Amount',
|
|
536
|
+
order: standardFields.fundraise.order * 10
|
|
537
|
+
}, {
|
|
538
|
+
name: 'Fundraise Valuation',
|
|
539
|
+
order: standardFields.fundraise.order * 10 + 1
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
if (standardFields.sources.active && standardFields.sources.showOnList) {
|
|
544
|
+
result.push({
|
|
545
|
+
name: 'Source',
|
|
546
|
+
order: standardFields.sources.order * 10
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (standardFields.referrers.active && standardFields.referrers.showOnList) {
|
|
551
|
+
result.push({
|
|
552
|
+
name: 'Referrers',
|
|
553
|
+
order: standardFields.referrers.order * 10
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// Add the custom fields
|
|
558
|
+
_.each(customFields, function(field) {
|
|
559
|
+
if (field.display.showOnList) {
|
|
560
|
+
result.push({
|
|
561
|
+
name: field.label,
|
|
562
|
+
order: field.display.order * 10
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
// Sort the combined standard and custom fields
|
|
568
|
+
result = _.sortBy(result, function(item) { return item.order; });
|
|
569
|
+
|
|
570
|
+
// Put the ever-present fields at the beginning
|
|
571
|
+
result.unshift({
|
|
572
|
+
name: 'Company',
|
|
573
|
+
order: 0
|
|
574
|
+
}, {
|
|
575
|
+
name: 'Stage',
|
|
576
|
+
order: 1
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// Now that we have all fields combined and ordered, make column order zero-indexed and gap-free
|
|
580
|
+
result = _.map(result, function(item, index) {
|
|
581
|
+
item.order = index;
|
|
582
|
+
return item;
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
return result;
|
|
586
|
+
|
|
587
|
+
});
|
|
588
|
+
|
|
459
589
|
Organization.virtual('employees.all').get(function () {
|
|
460
590
|
|
|
461
591
|
var self = this;
|