Skip to content

Commit 6fd078d

Browse files
committed
Merge pull request #347 from angular-ui/update-sample
Issue #345. Update sample.
2 parents b2cd6d2 + 288297d commit 6fd078d

13 files changed

+449
-245
lines changed

Gruntfile.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ module.exports = function (grunt) {
7070
tasks: ['build', 'karma:background:run']
7171
},
7272
connect: {
73-
server: {}
73+
server: {},
74+
sample: {
75+
options:{
76+
port: 5555,
77+
keepalive: true
78+
}
79+
}
7480
},
7581
karma: {
7682
options: {
@@ -91,6 +97,7 @@ module.exports = function (grunt) {
9197
grunt.registerTask('dist', 'Perform a clean build and generate documentation', ['clean', 'build', 'jsdoc']);
9298
grunt.registerTask('release', 'Tag and perform a release', ['prepare-release', 'dist', 'perform-release']);
9399
grunt.registerTask('dev', 'Run dev server and watch for changes', ['build', 'connect', 'karma:background', 'watch']);
100+
grunt.registerTask('sample', 'Run connect server with keepalive:true for sample app development', ['connect:sample']);
94101

95102
grunt.registerTask('jsdoc', 'Generate documentation', function () {
96103
promising(this,

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@
3838
"grunt-karma": "~0.4.3",
3939
"jsdoc": "git://github.com/jsdoc3/jsdoc.git#v3.1.1",
4040
"shelljs": "~0.1.4",
41-
"faithful-exec": "~0.1.0"
41+
"faithful-exec": "~0.1.0",
42+
"karma-firefox-launcher": "~0.1.0",
43+
"karma-chrome-launcher": "~0.1.0",
44+
"karma-html2js-preprocessor": "~0.1.0",
45+
"karma-jasmine": "~0.1.0",
46+
"karma-requirejs": "~0.1.0",
47+
"karma-script-launcher": "~0.1.0",
48+
"karma-coffee-preprocessor": "~0.1.0",
49+
"karma": "~0.10.1",
50+
"karma-phantomjs-launcher": "~0.1.0"
4251
}
4352
}

sample/contacts.detail.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<div>
22
<h2>{{contact.name}}</h2>
3-
<p class="muted">{{something}}</p>
43
<ul>
54
<li ng-repeat="item in contact.items">
6-
<a href="#/contacts/{{contact.id}}/item/{{item.id}}">{{item.type}}</a>
5+
<a ui-sref="contacts.detail.item({contactId:contact.id, itemId:item.id})">{{item.type}}</a>
76
</li>
87
</ul>
9-
<div ui-view ng-animate="{enter:'fade-enter'}"></div>
8+
<div ui-view ng-animate="{enter:'fade-enter'}">
9+
<!-- Example of default content. This content will be replace as soon as
10+
this ui-view is populate with a template -->
11+
<small class="muted">Click on a contact item to view and/or edit it.</small>
12+
</div>
1013
</div>

sample/contacts.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
<div class="span3">
33
<div class="pa-sidebar well well-small">
44
<ul class="nav nav-list">
5-
<li ng-class="{ active: $state.includes('contacts.list') }"><a href="#/contacts">All Contacts</a></li>
5+
<li ng-class="{ active: $state.includes('contacts.list') }"><a ui-sref="contacts.list">All Contacts</a></li>
66
<li class="nav-header">Top Contacts</li>
77
<li ng-repeat="contact in contacts | limitTo:2"
88
ng-class="{ active: $state.includes('contacts.detail') && $stateParams.contactId == contact.id }">
9-
<a href="#/contacts/{{contact.id}}" >{{contact.name}}</a>
9+
<a ui-sref="contacts.detail({contactId:contact.id})">{{contact.name}}</a>
1010
</li>
1111
</ul>
1212
<hr>
1313
<button class="btn" ng-click="goToRandom()">Show random contact</button>
14-
<div ui-view="menu"></div>
14+
<div ui-view="menuTip"></div>
1515
</div>
1616
</div>
1717
<div class="span9" ui-view ng-animate="{enter:'fade-enter'}"></div>

sample/contacts.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"contacts":[
3+
{
4+
"id": 1,
5+
"name": "Alice",
6+
"items": [
7+
{
8+
"id": "a",
9+
"type": "phone number",
10+
"value": "555-1234-1234"
11+
},
12+
{
13+
"id": "b",
14+
"type": "email",
15+
"value": "[email protected]"
16+
}
17+
]
18+
},
19+
{
20+
"id": 42,
21+
"name": "Bob",
22+
"items": [
23+
{
24+
"id": "a",
25+
"type": "blog",
26+
"value": "http://bob.blogger.com"
27+
},
28+
{
29+
"id": "b",
30+
"type": "fax",
31+
"value": "555-999-9999"
32+
}
33+
]
34+
},
35+
{
36+
"id": 123,
37+
"name": "Eve",
38+
"items": [
39+
{
40+
"id": "a",
41+
"type": "full name",
42+
"value": "Eve Adamsdottir"
43+
}
44+
]
45+
}
46+
]
47+
}

sample/contacts.list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h2>All Contacts</h2>
22
<ul>
33
<li ng-repeat="contact in contacts">
4-
<a href="#/contacts/{{contact.id}}">{{contact.name}}</a>
4+
<a ui-sref="contacts.detail({contactId:contact.id})">{{contact.name}}</a>
55
</li>
66
</ul>

sample/empty.content.html

Lines changed: 0 additions & 3 deletions
This file was deleted.

sample/empty.html

Lines changed: 0 additions & 5 deletions
This file was deleted.

sample/factory.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
angular.module('uiRouterSample')
2+
3+
// A RESTful factory for retreiving contacts from 'contacts.json'
4+
.factory('contacts', ['$http', function ($http, utils) {
5+
var path = 'contacts.json';
6+
var contacts = $http.get(path).then(function (resp) {
7+
return resp.data.contacts;
8+
});
9+
10+
var factory = {};
11+
factory.all = function () {
12+
return contacts;
13+
};
14+
factory.get = function (id) {
15+
return contacts.then(function(){
16+
return utils.findById(contacts, id);
17+
})
18+
};
19+
return factory;
20+
}])
21+
22+
.factory('utils', function () {
23+
24+
return {
25+
26+
// Util for finding an object by its 'id' property among an array
27+
findById: function findById(a, id) {
28+
for (var i = 0; i < a.length; i++) {
29+
if (a[i].id == id) return a[i];
30+
}
31+
return null;
32+
},
33+
34+
// Util for returning a randomKey from a collection that also isn't the current key
35+
newRandomKey: function newRandomKey(coll, key, currentKey){
36+
var randKey;
37+
do {
38+
randKey = coll[Math.floor(coll.length * Math.random())][key];
39+
} while (randKey == currentKey);
40+
return randKey;
41+
}
42+
43+
};
44+
45+
});

0 commit comments

Comments
 (0)