Skip to content

Commit 3018759

Browse files
committed
Added modal functionality
1 parent 2aaf61f commit 3018759

File tree

6 files changed

+68
-2
lines changed

6 files changed

+68
-2
lines changed

app/scripts/controllers/main.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
angular.module('codeSearchApp')
4-
.controller('MainCtrl', function ($scope, $http, $timeout) {
4+
.controller('MainCtrl', function ($scope, $http, $timeout, $modal, $log) {
55
$scope.isCollapsed = {collapse:false};
66
$scope.codeSnippits = [];
77
$scope.fileUrl = {url: ''};
@@ -53,4 +53,25 @@ angular.module('codeSearchApp')
5353
});
5454
};
5555

56+
$scope.open = function(size, snippitData) {
57+
58+
var modalInstance = $modal.open({
59+
templateUrl: '/partials/codesnippetmodal',
60+
controller: 'ModalCtrl',
61+
size: size,
62+
resolve: {
63+
data: function() {
64+
return {
65+
snippitData: snippitData
66+
}
67+
}
68+
}
69+
});
70+
71+
modalInstance.result.then(function(selectedItem) {
72+
$scope.selected = selectedItem;
73+
}, function() {
74+
$log.info('Modal dismissed at: ' + new Date());
75+
});
76+
};
5677
});

app/scripts/controllers/modal.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
angular.module('codeSearchApp')
4+
.controller('ModalCtrl', function ($scope, $http, $modalInstance, data) {
5+
6+
$scope.ok = function () {
7+
$modalInstance.dismiss('cancel');
8+
};
9+
10+
$scope.snippitData = data.snippitData;
11+
12+
});

app/views/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<script src="scripts/controllers/snippit.js"></script>
7272
<script src="scripts/filters/startpagefrom.js"></script>
7373
<script src="scripts/filters/paginatefrom.js"></script>
74+
<script src="scripts/controllers/modal.js"></script>
7475
<!-- endbuild -->
7576
</body>
7677
</html>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div>
2+
<pre>{{snippitData}}</pre>
3+
</div>
4+
<a style="color: black;" ng-click="ok()">&times;</a>

app/views/partials/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h3>Results:</h3>
9191
<div class="snippit" ng-repeat="snippit in codeSnippits |
9292
startPageFrom : page.currPage*page.resultsPerPage |
9393
limitTo : page.resultsPerPage track by $index">
94-
<pre>{{snippit}}</pre>
94+
<pre ng-click="open('lg', snippit)">{{snippit}}</pre>
9595
</div>
9696
<div>
9797
<button ng-disabled="page.currPage === 0"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
describe('Controller: ModalctrlCtrl', function () {
4+
5+
// load the controller's module
6+
beforeEach(module('codeSearchApp'));
7+
8+
var ModalCtrl,
9+
scope,
10+
$httpBackend;
11+
12+
// Initialize the controller and a mock scope
13+
beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
14+
$httpBackend = _$httpBackend_;
15+
$httpBackend.expectGET('/api/awesomeThings')
16+
.respond(['HTML5 Boilerplate', 'AngularJS', 'Karma', 'Express']);
17+
scope = $rootScope.$new();
18+
ModalCtrl = $controller('ModalCtrl', {
19+
$scope: scope
20+
});
21+
}));
22+
23+
it('should attach a list of awesomeThings to the scope', function () {
24+
expect(scope.awesomeThings).toBeUndefined();
25+
$httpBackend.flush();
26+
expect(scope.awesomeThings.length).toBe(4);
27+
});
28+
});

0 commit comments

Comments
 (0)