forked from mattcreager/talks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mattcreager/talks
- Loading branch information
Showing
23 changed files
with
520 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
* { | ||
box-sizing: border-box; | ||
} | ||
|
||
.unit { | ||
padding: 5px; | ||
padding-left: 0; | ||
padding-right: 0; | ||
background: white; | ||
color: black; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.unit-name { | ||
font-size: 16px; | ||
font-weight: bold; | ||
padding-right: 5px; | ||
} | ||
|
||
.unit description { | ||
display: block; | ||
margin: 5px 0; | ||
} | ||
|
||
.roster-name { | ||
color: green; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
angular.module('Buildr', []); | ||
/* global angular */ | ||
|
||
angular.module('Buildr', [ | ||
'truncate' | ||
]); |
26 changes: 26 additions & 0 deletions
26
realtime-angular-model/buildr/public/js/rosters/roster_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global angular */ | ||
|
||
(function() { | ||
|
||
'use strict'; | ||
|
||
angular | ||
.module('Buildr') | ||
.controller('RosterCtrl', ['$scope', 'rosterFactory', function($scope, rosterFactory) { | ||
var roster_id = '8dc743a3af53d898'; | ||
|
||
rosterFactory | ||
.get(roster_id) | ||
.then(function(roster) { | ||
$scope.roster = roster; | ||
|
||
console.log($scope.roster); | ||
}).finally($scope.$apply.bind($scope)); | ||
|
||
$scope.remove = function(roster) { | ||
roster.$remove(); | ||
}; | ||
}]); | ||
|
||
})(); | ||
|
74 changes: 74 additions & 0 deletions
74
realtime-angular-model/buildr/public/js/rosters/roster_model.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* global angular, EventEmitter, _ */ | ||
|
||
(function() { 'use strict'; | ||
|
||
angular | ||
.module('Buildr') | ||
.factory('rosterFactory', ['$timeout', 'rosterService', function($timeout, rosterService) { | ||
return { | ||
get: function(id) { | ||
return rosterService.get(id).then(function(rosters) { | ||
if (!_.isArray(rosters)) { | ||
return new RosterModel($timeout, rosterService, rosters); | ||
} | ||
|
||
return _.map(rosters, function(roster) { | ||
return new RosterModel($timeout, rosterService, roster); | ||
}); | ||
}); | ||
} | ||
}; | ||
}]); | ||
|
||
function RosterModel($timeout, rosterService, roster) { | ||
_.extend(this, { | ||
$$service: rosterService, | ||
$$timeout: $timeout | ||
}); | ||
|
||
_.merge(this, roster); | ||
} | ||
|
||
RosterModel.prototype.$inc = function(unit) { | ||
var self = this; | ||
|
||
this.$$timeout(function() { | ||
unit.count++; | ||
}); | ||
|
||
return this.$$service.inc(this.id, unit.id); | ||
}; | ||
|
||
RosterModel.prototype.$add = function(unit) { | ||
var self = this; | ||
|
||
if (_.find(this.units, { id: unit.id })) { | ||
return this.$inc(unit); | ||
} | ||
|
||
this.$$timeout(function() { | ||
self.units.push(unit); | ||
}); | ||
|
||
return this.$$service.addUnit(this.id, { | ||
unit_id: unit.id, | ||
count: 1 | ||
}); | ||
}; | ||
|
||
RosterModel.prototype.$remove = function(unit) { | ||
this.units.splice(this.units.indexOf(unit), 1); | ||
|
||
var units = _.map(this.units, function(unit) { | ||
return { | ||
unit_id: unit.id, | ||
count: unit.count | ||
}; | ||
}); | ||
|
||
return this.$$service.removeUnit(this.id, units); | ||
}; | ||
|
||
RosterModel.prototype.$$emitter = _.clone(EventEmitter.prototype); | ||
|
||
})(); |
76 changes: 76 additions & 0 deletions
76
realtime-angular-model/buildr/public/js/rosters/roster_service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* global angular, Q, _, dpd */ | ||
|
||
(function() { 'use strict'; | ||
|
||
angular | ||
.module('Buildr') | ||
.factory('rosterService', ['$http', 'unitFactory', function($http, unitFactory) { | ||
return new RosterService($http, unitFactory); | ||
}]); | ||
|
||
function RosterService($http, unitFactory) { | ||
_.extend(this, { | ||
$$http: $http, | ||
$$unitFactory: unitFactory, | ||
$$path: '/rosters' | ||
}); | ||
} | ||
|
||
RosterService.prototype.get = function(id) { | ||
var self = this; | ||
var deferred = Q.defer(); | ||
var path = id ? this.$$path + '/' + id : this.$$path; | ||
|
||
this.$$http | ||
.get(path) | ||
.success(function(result) { | ||
var units = _.map(result.units, function(unit) { | ||
return self.$$unitFactory.get(unit.unit_id).then(function(unitModel) { | ||
return _.merge(unitModel, unit); | ||
}); | ||
}); | ||
|
||
Q.all(units).then(function(units) { | ||
result.units = units; | ||
|
||
deferred.resolve(result); | ||
}); | ||
}) | ||
.error(deferred.reject); | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
RosterService.prototype.addUnit = function(id, unitData) { | ||
var deferred = Q.defer(); | ||
|
||
dpd.rosters.put(id, { | ||
units: { $push: unitData } | ||
}, function(result, err) { | ||
if (!result) return deferred.reject(err); | ||
|
||
deferred.resolve(result); | ||
}); | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
RosterService.prototype.removeUnit = function(id, units) { | ||
var deferred = Q.defer(); | ||
|
||
dpd.rosters.put(id, { units: units }, function(result, err) { | ||
if (err) return deferred.reject(err); | ||
|
||
deferred.resolve(result); | ||
}); | ||
|
||
return deferred.promise; | ||
}; | ||
|
||
RosterService.prototype.inc = function(id, unitId) { | ||
dpd.rosters.put(id, { 'units.unit_id': unitId }, { $inc: { count: 1 } }, function(result, err) { | ||
console.log(result, err); | ||
}); | ||
}; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
realtime-angular-model/buildr/resources/rosters/config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"type": "Collection", | ||
"properties": { | ||
"name": { | ||
"name": "name", | ||
"type": "string", | ||
"typeLabel": "string", | ||
"required": true, | ||
"id": "name", | ||
"order": 0 | ||
}, | ||
"units": { | ||
"name": "units", | ||
"type": "array", | ||
"typeLabel": "array", | ||
"required": false, | ||
"id": "units", | ||
"order": 1 | ||
} | ||
} | ||
} |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.