Skip to content

Commit 34e0d88

Browse files
committed
Merge pull request #108 from teamsnap/stats-fixes
Reload eventStatistics team-wide
2 parents 8260610 + 4f6d076 commit 34e0d88

File tree

8 files changed

+114
-93
lines changed

8 files changed

+114
-93
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# TeamSnap JavaScript SDK CHANGELOG
22

3+
### Jan 20, 2016 // Version 1.7.5
4+
- Reload `eventStatistics` teamwide when changes to `statistics` or `statisticData`.
5+
6+
---
7+
38
### Jan 14, 2016 // Version 1.7.4
49
- Reload `memberEmailAddress` and `contactEmailAddress` when sending `invite`.
510

lib/teamsnap.js

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,52 +8,53 @@ var window, global = {};
88

99
var modules = {};
1010
var cache = {};
11-
var aliases = {};
1211
var has = ({}).hasOwnProperty;
1312

13+
var aliases = {};
14+
1415
var endsWith = function(str, suffix) {
1516
return str.indexOf(suffix, str.length - suffix.length) !== -1;
1617
};
1718

18-
var _cmp = 'components/';
1919
var unalias = function(alias, loaderPath) {
2020
var start = 0;
2121
if (loaderPath) {
22-
if (loaderPath.indexOf(_cmp) === 0) {
23-
start = _cmp.length;
22+
if (loaderPath.indexOf('components/' === 0)) {
23+
start = 'components/'.length;
2424
}
2525
if (loaderPath.indexOf('/', start) > 0) {
2626
loaderPath = loaderPath.substring(start, loaderPath.indexOf('/', start));
2727
}
2828
}
2929
var result = aliases[alias + '/index.js'] || aliases[loaderPath + '/deps/' + alias + '/index.js'];
3030
if (result) {
31-
return _cmp + result.substring(0, result.length - '.js'.length);
31+
return 'components/' + result.substring(0, result.length - '.js'.length);
3232
}
3333
return alias;
3434
};
3535

36-
var _reg = /^\.\.?(\/|$)/;
37-
var expand = function(root, name) {
38-
var results = [], part;
39-
var parts = (_reg.test(name) ? root + '/' + name : name).split('/');
40-
for (var i = 0, length = parts.length; i < length; i++) {
41-
part = parts[i];
42-
if (part === '..') {
43-
results.pop();
44-
} else if (part !== '.' && part !== '') {
45-
results.push(part);
36+
var expand = (function() {
37+
var reg = /^\.\.?(\/|$)/;
38+
return function(root, name) {
39+
var results = [], parts, part;
40+
parts = (reg.test(name) ? root + '/' + name : name).split('/');
41+
for (var i = 0, length = parts.length; i < length; i++) {
42+
part = parts[i];
43+
if (part === '..') {
44+
results.pop();
45+
} else if (part !== '.' && part !== '') {
46+
results.push(part);
47+
}
4648
}
47-
}
48-
return results.join('/');
49-
};
50-
49+
return results.join('/');
50+
};
51+
})();
5152
var dirname = function(path) {
5253
return path.split('/').slice(0, -1).join('/');
5354
};
5455

5556
var localRequire = function(path) {
56-
return function expanded(name) {
57+
return function(name) {
5758
var absolute = expand(dirname(path), name);
5859
return globals.require(absolute, path);
5960
};
@@ -108,7 +109,6 @@ var window, global = {};
108109
};
109110

110111
require.brunch = true;
111-
require._cache = cache;
112112
globals.require = require;
113113
})();
114114
var require = global.require;
@@ -4392,8 +4392,19 @@ modifySDK = function(sdk) {
43924392
var toRemove;
43934393
toRemove = statistic.statisticData.slice();
43944394
toRemove.push.apply(toRemove, statistic.eventStatistics);
4395+
toRemove.push.apply(toRemove, statistic.memberStatistics);
4396+
toRemove.push.apply(toRemove, statistic.teamStatistics);
4397+
toRemove.push.apply(toRemove, statistic.statisticAggregates);
43954398
linking.unlinkItems(toRemove, lookup);
4396-
return deleteStatistic.call(this, statistic).fail(function(err) {
4399+
return deleteStatistic.call(this, statistic).then(function(result) {
4400+
var bulkLoadTypes, statisticId, teamId;
4401+
teamId = statistic.teamId;
4402+
statisticId = result.id;
4403+
bulkLoadTypes = ['memberStatistic', 'teamStatistic', 'statisticAggregate', 'eventStatistic'];
4404+
return sdk.bulkLoad(teamId, bulkLoadTypes).then(function() {
4405+
return result;
4406+
});
4407+
}).fail(function(err) {
43974408
linking.linkItems(toRemove, lookup);
43984409
return err;
43994410
}).callback(callback);
@@ -4408,10 +4419,8 @@ modifySDK = function(sdk) {
44084419
var bulkLoadTypes, statisticId, teamId;
44094420
teamId = statistic.teamId;
44104421
statisticId = result.id;
4411-
bulkLoadTypes = ['memberStatistic', 'teamStatistic', 'statisticAggregate', 'statistic', 'statisticGroup'];
4412-
return promises.when(sdk.bulkLoad(teamId, bulkLoadTypes), sdk.loadEventStatistics({
4413-
statisticId: statisticId
4414-
})).then(function() {
4422+
bulkLoadTypes = ['memberStatistic', 'teamStatistic', 'statisticAggregate', 'statistic', 'statisticGroup', 'eventStatistic'];
4423+
return sdk.bulkLoad(teamId, bulkLoadTypes).then(function() {
44154424
return result;
44164425
});
44174426
}).callback(callback);
@@ -4420,14 +4429,11 @@ modifySDK = function(sdk) {
44204429
wrapMethod(sdk, 'bulkSaveStatisticData', function(bulkSaveStatisticData) {
44214430
return function(templates, callback) {
44224431
return bulkSaveStatisticData.call(this, templates, callback).then(function(result) {
4423-
var bulkLoadTypes, statisticId, teamId;
4432+
var bulkLoadTypes, teamId;
44244433
if ((result[0] != null) && (result[0].teamId != null)) {
44254434
teamId = result[0].teamId;
4426-
statisticId = result[0].statisticId;
4427-
bulkLoadTypes = ['memberStatistic', 'statisticAggregate'];
4428-
return promises.when(sdk.bulkLoad(teamId, bulkLoadTypes), sdk.loadEventStatistics({
4429-
statisticId: statisticId
4430-
})).then(function() {
4435+
bulkLoadTypes = ['memberStatistic', 'statisticAggregate', 'eventStatistic'];
4436+
return sdk.bulkLoad(teamId, bulkLoadTypes).then(function() {
44314437
return result;
44324438
});
44334439
}
@@ -4440,10 +4446,8 @@ modifySDK = function(sdk) {
44404446
var bulkLoadTypes, statisticId, teamId;
44414447
teamId = result.teamId;
44424448
statisticId = result.statisticId;
4443-
bulkLoadTypes = ['memberStatistic', 'statisticAggregate'];
4444-
return promises.when(sdk.bulkLoad(teamId, bulkLoadTypes), sdk.loadEventStatistics({
4445-
statisticId: statisticId
4446-
})).then(function() {
4449+
bulkLoadTypes = ['memberStatistic', 'statisticAggregate', 'eventStatistic'];
4450+
return sdk.bulkLoad(teamId, bulkLoadTypes).then(function() {
44474451
return result;
44484452
});
44494453
}).callback(callback);
@@ -4463,10 +4467,10 @@ modifySDK = function(sdk) {
44634467
}
44644468
linking.unlinkItems(toRemove, lookup);
44654469
return bulkDeleteStatisticData.call(this, member, event).then(function(result) {
4466-
var bulkLoadTypes, eventId, teamId;
4467-
return promises.when(teamId = member.teamId, eventId = event.id, bulkLoadTypes = ['memberStatistic', 'statisticAggregate'], sdk.bulkLoad(teamId, bulkLoadTypes), sdk.loadEventStatistics({
4468-
eventId: eventId
4469-
})).then(function() {
4470+
var bulkLoadTypes, teamId;
4471+
teamId = member.teamId;
4472+
bulkLoadTypes = ['memberStatistic', 'statisticAggregate', 'eventStatistic'];
4473+
return sdk.bulkLoad(teamId, bulkLoadTypes).then(function() {
44704474
return result;
44714475
});
44724476
}).fail(function(err) {
@@ -5745,7 +5749,7 @@ ref = require('./model'), Collection = ref.Collection, Item = ref.Item;
57455749
require('./errors');
57465750

57475751
TeamSnap = (function() {
5748-
TeamSnap.prototype.version = '1.7.4';
5752+
TeamSnap.prototype.version = '1.7.5';
57495753

57505754
TeamSnap.prototype.promises = promises;
57515755

lib/teamsnap.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/test/js/test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,53 @@
66

77
var modules = {};
88
var cache = {};
9-
var aliases = {};
109
var has = ({}).hasOwnProperty;
1110

11+
var aliases = {};
12+
1213
var endsWith = function(str, suffix) {
1314
return str.indexOf(suffix, str.length - suffix.length) !== -1;
1415
};
1516

16-
var _cmp = 'components/';
1717
var unalias = function(alias, loaderPath) {
1818
var start = 0;
1919
if (loaderPath) {
20-
if (loaderPath.indexOf(_cmp) === 0) {
21-
start = _cmp.length;
20+
if (loaderPath.indexOf('components/' === 0)) {
21+
start = 'components/'.length;
2222
}
2323
if (loaderPath.indexOf('/', start) > 0) {
2424
loaderPath = loaderPath.substring(start, loaderPath.indexOf('/', start));
2525
}
2626
}
2727
var result = aliases[alias + '/index.js'] || aliases[loaderPath + '/deps/' + alias + '/index.js'];
2828
if (result) {
29-
return _cmp + result.substring(0, result.length - '.js'.length);
29+
return 'components/' + result.substring(0, result.length - '.js'.length);
3030
}
3131
return alias;
3232
};
3333

34-
var _reg = /^\.\.?(\/|$)/;
35-
var expand = function(root, name) {
36-
var results = [], part;
37-
var parts = (_reg.test(name) ? root + '/' + name : name).split('/');
38-
for (var i = 0, length = parts.length; i < length; i++) {
39-
part = parts[i];
40-
if (part === '..') {
41-
results.pop();
42-
} else if (part !== '.' && part !== '') {
43-
results.push(part);
34+
var expand = (function() {
35+
var reg = /^\.\.?(\/|$)/;
36+
return function(root, name) {
37+
var results = [], parts, part;
38+
parts = (reg.test(name) ? root + '/' + name : name).split('/');
39+
for (var i = 0, length = parts.length; i < length; i++) {
40+
part = parts[i];
41+
if (part === '..') {
42+
results.pop();
43+
} else if (part !== '.' && part !== '') {
44+
results.push(part);
45+
}
4446
}
45-
}
46-
return results.join('/');
47-
};
48-
47+
return results.join('/');
48+
};
49+
})();
4950
var dirname = function(path) {
5051
return path.split('/').slice(0, -1).join('/');
5152
};
5253

5354
var localRequire = function(path) {
54-
return function expanded(name) {
55+
return function(name) {
5556
var absolute = expand(dirname(path), name);
5657
return globals.require(absolute, path);
5758
};
@@ -106,7 +107,6 @@
106107
};
107108

108109
require.brunch = true;
109-
require._cache = cache;
110110
globals.require = require;
111111
})();
112112
require.register("test/assignments", function(exports, require, module) {

lib/test/js/test.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "teamsnap.js",
3-
"version": "1.7.4",
3+
"version": "1.7.5",
44
"description": "A JavaScript library for using the TeamSnap API.",
55
"author": "Jacob Wright with TeamSnap (http://www.teamsnap.com)",
66
"homepage": "https://github.com/teamsnap/teamsnap-javascript-sdk",

src/persistence.coffee

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,22 @@ modifySDK = (sdk) ->
397397
(statistic, callback) ->
398398
toRemove = statistic.statisticData.slice()
399399
toRemove.push statistic.eventStatistics...
400+
toRemove.push statistic.memberStatistics...
401+
toRemove.push statistic.teamStatistics...
402+
toRemove.push statistic.statisticAggregates...
400403

401404
linking.unlinkItems toRemove, lookup
402-
deleteStatistic.call(this, statistic).fail((err) ->
405+
deleteStatistic.call(this, statistic).then((result) ->
406+
teamId = statistic.teamId
407+
statisticId = result.id
408+
bulkLoadTypes = [
409+
'memberStatistic',
410+
'teamStatistic',
411+
'statisticAggregate',
412+
'eventStatistic'
413+
]
414+
sdk.bulkLoad(teamId, bulkLoadTypes).then -> result
415+
).fail((err) ->
403416
linking.linkItems toRemove, lookup
404417
err
405418
).callback callback
@@ -419,13 +432,11 @@ modifySDK = (sdk) ->
419432
'teamStatistic',
420433
'statisticAggregate',
421434
'statistic',
422-
'statisticGroup'
435+
'statisticGroup',
436+
'eventStatistic'
423437
]
424438

425-
promises.when(
426-
sdk.bulkLoad(teamId, bulkLoadTypes)
427-
sdk.loadEventStatistics statisticId: statisticId
428-
).then -> result
439+
sdk.bulkLoad(teamId, bulkLoadTypes).then -> result
429440
).callback callback
430441

431442
# Update member statistics when saving statisticData
@@ -434,12 +445,12 @@ modifySDK = (sdk) ->
434445
bulkSaveStatisticData.call(this, templates, callback).then((result) ->
435446
if result[0]? and result[0].teamId?
436447
teamId = result[0].teamId
437-
statisticId = result[0].statisticId
438-
bulkLoadTypes = ['memberStatistic', 'statisticAggregate']
439-
promises.when(
440-
sdk.bulkLoad(teamId, bulkLoadTypes)
441-
sdk.loadEventStatistics statisticId: statisticId
442-
).then -> result
448+
bulkLoadTypes = [
449+
'memberStatistic',
450+
'statisticAggregate',
451+
'eventStatistic'
452+
]
453+
sdk.bulkLoad(teamId, bulkLoadTypes).then -> result
443454
).callback callback
444455

445456
wrapMethod sdk, 'saveStatisticDatum', (saveStatisticDatum) ->
@@ -448,11 +459,12 @@ modifySDK = (sdk) ->
448459
.then((result) ->
449460
teamId = result.teamId
450461
statisticId = result.statisticId
451-
bulkLoadTypes = ['memberStatistic', 'statisticAggregate']
452-
promises.when(
453-
sdk.bulkLoad(teamId, bulkLoadTypes)
454-
sdk.loadEventStatistics statisticId: statisticId
455-
).then -> result
462+
bulkLoadTypes = [
463+
'memberStatistic',
464+
'statisticAggregate',
465+
'eventStatistic'
466+
]
467+
sdk.bulkLoad(teamId, bulkLoadTypes).then -> result
456468
).callback callback
457469

458470
# Remove deleted member statisticData when using bulk delete command
@@ -466,13 +478,13 @@ modifySDK = (sdk) ->
466478
linking.unlinkItems toRemove, lookup
467479

468480
bulkDeleteStatisticData.call(this, member, event).then((result) ->
469-
promises.when(
470-
teamId = member.teamId
471-
eventId = event.id
472-
bulkLoadTypes = ['memberStatistic', 'statisticAggregate']
473-
sdk.bulkLoad(teamId, bulkLoadTypes)
474-
sdk.loadEventStatistics eventId: eventId
475-
).then -> result
481+
teamId = member.teamId
482+
bulkLoadTypes = [
483+
'memberStatistic',
484+
'statisticAggregate',
485+
'eventStatistic'
486+
]
487+
sdk.bulkLoad(teamId, bulkLoadTypes).then -> result
476488
).fail((err) ->
477489
linking.linkItems toRemove, lookup
478490
err

src/teamsnap.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ promises = require './promises'
33
require './errors'
44

55
class TeamSnap
6-
version: '1.7.4'
6+
version: '1.7.5'
77
promises: promises
88
when: promises.when
99
TeamSnap: TeamSnap

0 commit comments

Comments
 (0)