Skip to content

Commit

Permalink
Add: newLinkEntry client side
Browse files Browse the repository at this point in the history
  • Loading branch information
meip committed Nov 27, 2013
1 parent b7e56e5 commit 44aaf02
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 6 deletions.
6 changes: 6 additions & 0 deletions client/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ angular.module('dpreddit-angular', ['ngCookies', 'ngRoute'])
controller: 'PrivateCtrl',
access: access.user
});
$routeProvider.when('/newlinkentry',
{
templateUrl: 'newlinkentry',
controller: 'NewLinkEntryCtrl',
access: access.user
});
$routeProvider.when('/404',
{
templateUrl: '404',
Expand Down
33 changes: 29 additions & 4 deletions client/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,29 @@ angular.module('dpreddit-angular')

angular.module('dpreddit-angular')
.controller('HomeCtrl',
['$rootScope', function ($rootScope) {
['$rootScope', '$scope', 'LinkEntry', function ($rootScope, $scope, LinkEntry) {

$scope.loading = true;
LinkEntry.getAll(function (res) {
$scope.linkEntries = res;
$scope.loading = false;
}, function (err) {
$rootScope.error = "Failed to fetch LinkEntry.getAll.";
$scope.loading = false;
});

}]);

angular.module('dpreddit-angular')
.controller('RegisterCtrl',
['$rootScope', '$scope', '$location', 'Auth', function ($rootScope, $scope, $location, Auth) {
$scope.role = Auth.userRoles.user;
$scope.userRoles = Auth.userRoles;

$scope.register = function () {
Auth.register({
username: $scope.username,
password: $scope.password,
passwordrepeat: $scope.passwordrepeat,
role: $scope.role
role: Auth.userRoles.user
},
function () {
$location.path('/');
Expand All @@ -69,6 +76,24 @@ angular.module('dpreddit-angular')
};
}]);

angular.module('dpreddit-angular')
.controller('NewLinkEntryCtrl',
['$rootScope', '$scope', '$location', 'LinkEntry', function ($rootScope, $scope, $location, LinkEntry) {

$scope.addnewlinkentry = function () {
LinkEntry.addnewlinkentry({
linkentrytitle: $scope.newlinkentrytitle,
linkentryurl: $scope.newlinkentryurl
},
function () {
$location.path('/');
},
function (err) {
$rootScope.error = err;
});
};
}]);

angular.module('dpreddit-angular')
.controller('PrivateCtrl',
['$rootScope', function ($rootScope) {
Expand Down
14 changes: 14 additions & 0 deletions client/js/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ angular.module('dpreddit-angular')
}
};
});

angular.module('dpreddit-angular')
.factory('LinkEntry', function ($http) {
return {
getAll: function (success, error) {
$http.get('/linkentries').success(success).error(error);
},
addnewlinkentry: function (newlinkentry, success, error) {
$http.post('/addnewlinkentry', newlinkentry).success(function (res) {
success();
}).error(error);
}
};
});
2 changes: 2 additions & 0 deletions client/views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ html(lang='en', data-ng-app='dpreddit-angular')
include partials/private
script(type="text/ng-template", id="register")
include partials/register
script(type="text/ng-template", id="newlinkentry")
include partials/newlinkentry
17 changes: 15 additions & 2 deletions client/views/partials/home.jade
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
h1 Hello
p This view is visible to logged in users.
h1 DPReddit-Angular Links
ul.media-list.list-group(data-ng-hide="loading")
li.media.list-group-item(data-ng-repeat="linkEntry in linkEntries")
div.pull-left
span.glyphicon.glyphicon-chevron-up
div.clearfix
span.glyphicon.glyphicon-chevron-down
div.media-body
a(href='{{linkEntry.linkurl}}')
h3 {{ linkEntry.title }}
span 1 minute ago
div
a(href='foo.html')  
span.glyphicon.glyphicon-comment
|  Comments
4 changes: 4 additions & 0 deletions client/views/partials/navbar.jade
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
a.navbar-brand(href="#") DPReddit-Angular
.collapse.navbar-collapse.navbar-ex1-collapse
ul.nav.navbar-nav
li(data-access-level='accessLevels.user')
a(href='/newlinkentry')
| Submit link  
span.glyphicon.glyphicon-link
ul.nav.navbar-nav.navbar-right
li(data-access-level='accessLevels.anon', active-nav)
a(href='/login') Log in
Expand Down
28 changes: 28 additions & 0 deletions client/views/partials/newlinkentry.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
div.row
div.col-sm-12
div.panel.panel-default
div.panel-body
div.panel-heading
h4 Submit a new link
form.form-horizontal(ng-submit="addnewlinkentry()", name="newlinkentryForm")
div.form-group
label.control-label.col-sm-2(for="linktitle") Title
div.col-sm-6
input.form-control.col-sm-6(type="text", data-ng-model="newlinkentrytitle", placeholder="Check this out", name="linktitle", required, data-ng-maxlength="100", autofocus)
div.form-group
label.control-label.col-sm-2(for="linkurl") Link URL
div.col-sm-6
input.form-control.col-sm-6(type="text", data-ng-model="newlinkentryurl", placeholder="http://whatever.com", name="linkurl", required, data-ng-maxlength="255")
div.form-group
.col-sm-offset-2.col-sm-10
input.btn.btn-warning(type="reset", value="Reset!", ng-click="newlinkentryForm.$setPristine()")
button.btn.btn-primary.col-sm-offset-5(type="submit", data-ng-disabled="newlinkentryForm.$invalid") Submit

.alert.alert-error(ng-show="newlinkentryForm.$invalid && newlinkentryForm.$dirty")
strong Please correct the following errors:
ul
li(ng-show="registerForm.newlinkentrytitle.$error.required") Link Title is required
li(ng-show="registerForm.newlinkentrytitle.$error.minlength") Link Title has to be at least 1 character long
li(ng-show="registerForm.newlinkentrytitle.$error.maxlength") Link Title has to be at most 100 character long
li(ng-show="registerForm.newlinkentryurl.$error.required") Link URL is required
li(ng-show="registerForm.newlinkentryurl.$error.maxlength") Link URL has to be at most 255 character long

0 comments on commit 44aaf02

Please sign in to comment.