Skip to content

Commit ef0cccb

Browse files
author
Arpit Jalan
committed
Create Read Delete implemented
1 parent 09247d3 commit ef0cccb

File tree

7 files changed

+51
-52
lines changed

7 files changed

+51
-52
lines changed
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
'use strict';
22

3-
ngApp.controller('DashboardCtrl', function($scope, Company, $rootScope) {
3+
var dashbord = ngApp.controller('DashboardCtrl', function($scope, Company, $rootScope, $routeParams, $modal) {
44
$rootScope.companies = Company.all();
5-
});
5+
6+
// open modal
7+
$scope.deleteCompany = function (company) {
8+
Company.delete(company.id);
9+
$rootScope.companies.splice( $rootScope.companies.indexOf(company), 1 );
10+
// $rootScope.companies.pop(company);
11+
};
12+
13+
$scope.editCompany = function modal(company) {
14+
// var company = $rootScope.companies[$rootScope.companies.indexOf(company)];
15+
// console.log($rootScope.companies);
16+
var modalInstance = $modal.open({
17+
backdrop: 'static',
18+
// param: $routeParams,
19+
templateUrl: '/templates/edit_company.html',
20+
controller: 'DashboardCtrl',
21+
resolve: {
22+
company: function () {
23+
return $rootScope.companies[$rootScope.companies.indexOf(company)];
24+
}
25+
}
26+
});
27+
};
28+
});

app/assets/stylesheets/application.css

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

app/controllers/api/companies_controller.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Api::CompaniesController < Api::BaseController
66
def index
77
# render json: current_user.companies
88
respond_with current_user.companies
9+
# respond_with Company.all
910
end
1011

1112
def show
@@ -24,17 +25,18 @@ def update
2425
end
2526

2627
def destroy
28+
# company = Company.find(params[:id])
2729
company.destroy
28-
render nothing: true
30+
render nothing: true, status: 204
2931
end
3032

3133
private
32-
def check_owner
33-
permission_denied if current_user != company.owner
34-
end
34+
# def check_owner
35+
# permission_denied if current_user != company.owner
36+
# end
3537

3638
def company
37-
@company ||= company.find(params[:id])
39+
@company ||= Company.find(params[:id])
3840
end
3941

4042
def safe_params

app/controllers/session_controller.rb

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

app/views/session/new.html.erb

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

app/views/templates/dashboard.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
<div>
1717
<span>submitted by <a href="#/users/{{ company.user_id }}">{{ company.owner }}</a></span>
1818
19-
<a href="/companies/{{ company.id }}">comments</a>
20-
<a ng-click="deletePost(company.id)" ng-show="signedIn() && company.owner === currentUser.username">delete</a>
19+
<a ng-click="editCompany(company.id)" href="#">edit</a>
20+
<a ng-click="deleteCompany(company)" href="#">delete</a>
2121
</div>
2222
</div>
2323
<div class="col-md-2">
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<form id="new_task" class="ng-pristine ng-valid" ng-submit="submitCompany()">
2+
<div class="modal-header">
3+
<h3>Submit Company</h3>
4+
</div>
5+
<div class="modal-body">
6+
<div class="form-group">
7+
<input type="text" placeholder="Company Name" ng-model="company.name" maxlength="255" id="taskDescription" data-non-blank="" class="form-control input-lg ng-pristine ng-valid" autofocus="autofocus" required>
8+
</div>
9+
<div class="form-group">
10+
<input type="text" placeholder="URL" ng-model="company.url" maxlength="255" id="taskDescription" data-non-blank="" class="form-control input-lg ng-pristine ng-valid" autofocus="autofocus" required>
11+
</div>
12+
</div>
13+
<div class="modal-footer">
14+
<button type="submit" class="btn btn-primary">Submit</button>
15+
<button type="button" class="btn btn-warning" ng-click="$close()">Cancel</button>
16+
</div>
17+
</form>

0 commit comments

Comments
 (0)