Skip to content

Commit 8b40c1a

Browse files
authored
Merge pull request #665 from Henry-Hao/issue-461
Issue 461
2 parents 12162eb + fcfa94d commit 8b40c1a

10 files changed

Lines changed: 251 additions & 7 deletions

File tree

app/app/Http/Controllers/LocationManagementController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ public function showCurrentUserLocations()
290290

291291
foreach ($locations as $location) {
292292
$location->is_safe_to_delete = in_array($location->id, $location_ids);
293+
$val = DB::table('suggestion')
294+
->where('location_id', '=', $location->id)
295+
->get()
296+
->count();
297+
$location->suggestions = $val;
293298
}
294299
$view_data = [
295300
'locations' => $locations

app/app/Http/Controllers/SuggestionController.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use App\Location;
1212
use App\BaseUser;
1313
use App\Suggestion;
14+
use App\User;
15+
use DB;
1416

1517
class SuggestionController extends Controller
1618
{
@@ -77,4 +79,39 @@ public function addSuggestion(Request $request)
7779
'success' => 1
7880
], 200);
7981
}
82+
83+
public function showSuggestionList(string $location_id)
84+
{
85+
$location_name = Location::find($location_id)->name;
86+
$suggestions = DB::table('suggestion')
87+
->where('location_id', '=', $location_id)
88+
->get([
89+
'id',
90+
'user_id',
91+
'when_generated']);
92+
foreach ($suggestions as $suggestion) {
93+
$user = User::find($suggestion->user_id);
94+
$suggestion->user_name = $user->first_name." ".$user->last_name;
95+
}
96+
$view_data = [
97+
'suggestions' => $suggestions,
98+
'name' => $location_name
99+
];
100+
return view('pages.location_management.suggestion_list', $view_data);
101+
}
102+
103+
public function showSuggestionDetail(string $suggestion_id)
104+
{
105+
$suggestion = Suggestion::find($suggestion_id);
106+
$location = Location::find($suggestion->location_id);
107+
$user = User::find($suggestion->user_id);
108+
$user_name = $user->first_name." ".$user->last_name;
109+
$view_data = [
110+
'suggestion' => $suggestion,
111+
'user_name' => $user_name,
112+
'location_name' => $location->name,
113+
'original_location' => $location
114+
];
115+
return view('pages.location_management.suggestion_detail', $view_data);
116+
}
80117
}

app/public/js/suggestion_detail.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
document.addEventListener("DOMContentLoaded", function(event) {
2+
bindField('accept_name');
3+
bindField('accept_phone_number');
4+
bindField('accept_address');
5+
bindField('accept_url');
6+
bindField('accept_all');
7+
});
8+
9+
function getData(fieldname){
10+
var data = {};
11+
data['_token'] = $('[name="_token"]').val();
12+
data['location_id'] = $("#location_id").val();
13+
14+
data['name'] = $("#original_name").val();
15+
data['address'] = $("#original_address").val();
16+
data['external_web_url'] = $("#original_url").val();
17+
data['phone_number'] = $("#original_phone_number").val();
18+
switch(fieldname){
19+
case "accept_name":
20+
data['name'] = $("#suggestion_name").val();
21+
break;
22+
case "accept_phone_number":
23+
data['phone_number'] = $("#suggestion_phone_number").val();
24+
break;
25+
case "accept_address":
26+
data['address'] = $("#suggestion_address").val();
27+
break;
28+
case "accept_url":
29+
data['external_web_url'] = $("#suggestion_url").val();
30+
break;
31+
case "accept_all":
32+
data['name'] = $("#suggestion_name").val();
33+
data['external_web_url'] = $("#suggestion_url").val();
34+
data['address'] = $("#suggestion_address").val();
35+
data['phone_number'] = $("#suggestion_phone_number").val();
36+
break;
37+
}
38+
39+
return data;
40+
}
41+
42+
function bindField(tag){
43+
$("#"+ tag).click(function(){
44+
sendRequest(getData(tag), tag);
45+
})
46+
}
47+
48+
function sendRequest(data,tag){
49+
$.ajax({
50+
url:"/location/management/edit",
51+
method:'post',
52+
data:data,
53+
success:function(){
54+
location.reload();
55+
},
56+
error:function(result){
57+
$("#" + tag).parent().prepend("<div class='alert alert-danger'>"
58+
+ "Something wrong happens."
59+
+ "</div>");
60+
}
61+
})
62+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
@import "_placeholders.scss";
2+
3+
.suggestion-detail {
4+
@extend %page-base;
5+
@extend %alternative-row-data;
6+
7+
input[type="text"] {
8+
margin-bottom: 10px;
9+
}
10+
11+
.alert-hide {
12+
display: none;
13+
}
14+
15+
a {
16+
text-decoration: none !important;
17+
}
18+
19+
.row {
20+
margin: 0px;
21+
}
22+
23+
.form, .form-group {
24+
padding: 10px;
25+
border: 1px solid rgba($color: #000000, $alpha: 0.5);
26+
border-radius: 10px;
27+
}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@import "_placeholders.scss";
2+
3+
.suggestion-list {
4+
@extend %page-base;
5+
@extend %alternative-row-data;
6+
7+
h1 {
8+
margin-top: 0;
9+
}
10+
11+
a {
12+
text-decoration: none !important;
13+
}
14+
15+
.list-group-item {
16+
padding-right: 20px;
17+
}
18+
19+
.username {
20+
padding-left: 5px;
21+
}
22+
23+
.when_generated {
24+
float: right;
25+
}
26+
27+
}

app/resources/assets/sass/app.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
@import "_sign_in.scss";
2929
@import "_sign_up.scss";
3030
@import "_social_media_buttons.scss";
31+
@import "_suggestion_list.scss";
32+
@import "_suggestion_detail.scss";
3133

3234
// Bootstrap
3335
@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";

app/resources/views/pages/location_management/locations_added_by_me.blade.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,30 @@
1010
@else
1111
<p class="add-create"><a href="/location/management/add" title="Add New Location"><em class="fa fa-plus-circle"></em></a></p>
1212
<div class="row column-titles">
13-
<div class="col-xs-4">
13+
<div class="col-xs-3">
1414
<h3>Name</h3>
1515
</div>
16-
<div class="col-md-6 col-xs-4">
16+
<div class="col-md-5 col-xs-3">
1717
<h3>Address</h3>
1818
</div>
19-
<div class="col-md-2 col-xs-4">
20-
<h3>Action</h3>
19+
<div class="col-md-3 col-xs-3">
20+
<h3>Suggestions</h3>
2121
</div>
2222

2323
</div>
2424
<div class="data">
2525
@foreach ($locations as $location)
2626
<div class="row">
27-
<div class="col-xs-4">
27+
<div class="col-xs-3">
2828
<a href="/location/rating/{{ $location->id }}">{{ $location->name }}</a>
2929
</div>
30-
<div class="col-md-6 col-xs-4">
30+
<div class="col-md-5 col-xs-3">
3131
<a href="/location/rating/{{ $location->id }}">{{ $location->address }}</a>
3232
</div>
33-
<div class="col-md-2 col-xs-4">
33+
<div class="col-md-2 col-xs-3">
34+
<a href="/suggestion-list/{{ $location->id }}">{{ $location->suggestions }}</a>
35+
</div>
36+
<div class="col-md-2 col-xs-3">
3437

3538
<div class="col-md-6 col-xs-6">
3639
<a href="/location/management/edit/{{ $location->id }}">Edit</a>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
@extends('layouts.default')
2+
@section('head-content')
3+
<script language="JavaScript" src="/js/jquery-3.1.1.js"></script>
4+
<script src="/js/suggestion_detail.js"></script>
5+
@stop
6+
@section('content')
7+
<div class="suggestion-detail">
8+
<div class="text-center">
9+
<h1>{{ $user_name }}'s <a href="/suggestion-list/{{ $suggestion->location_id }}">Suggestion for {{ $location_name }}</a></h1>
10+
</div>
11+
<form class="form">
12+
{!! csrf_field() !!}
13+
<input type="hidden" id="suggestion_id" value="{{ $suggestion->id }}">
14+
<input type="hidden" id="location_id" value="{{ $suggestion->location_id }}">
15+
<div class="row">
16+
<div class="form-group col-md-12">
17+
<div class="col-md-6">
18+
<label for="original_name">Name:</label>
19+
<input class="form-control" type="text" id="original_name" value="{{ $original_location->name }}" readonly>
20+
<input class="form-control" type="text" id="suggestion_name" value="{{ $suggestion->location_name }}" readonly>
21+
<input type="button" class="btn btn-primary" id="accept_name" value="Accept">
22+
<input type="button" class="btn btn-warning" value="Mark as Resolved">
23+
</div>
24+
<div class="col-md-6 ">
25+
<label for="original_phone_number">Phone Number:</label>
26+
<input class="form-control" type="text" id="original_phone_number" value="{{ $original_location->phone_number }}" readonly>
27+
<input class="form-control" type="text" id="suggestion_phone_number" value="{{ $suggestion->location_phone_number }}" readonly>
28+
<input type="button" class="btn btn-primary" id="accept_phone_number" value="Accept">
29+
<input type="button" class="btn btn-warning" value="Mark as Resolved">
30+
</div>
31+
</div>
32+
</div>
33+
34+
<div class="form-group">
35+
<label for="original_address">Address:</label>
36+
<input class="form-control" type="text" id="original_address" value="{{ $original_location->address }}" readonly>
37+
<input class="form-control" type="text" id="suggestion_address" value="{{ $suggestion->location_address }}" readonly>
38+
<input type="button" class="btn btn-primary" id="accept_address" value="Accept">
39+
<input type="button" class="btn btn-warning" value="Mark as Resolved">
40+
</div>
41+
42+
<div class="form-group">
43+
<label for="original_url">External Web Url:</label>
44+
<input class="form-control" type="text" id="original_url" value="{{ $original_location->external_web_url }}" readonly>
45+
<input class="form-control" type="text" id="suggestion_url" value="{{ $suggestion->location_external_web_url }}" readonly>
46+
<input type="button" class="btn btn-primary" id="accept_url" value="Accept">
47+
<input type="button" class="btn btn-warning" value="Mark as Resolved">
48+
</div>
49+
50+
<div>
51+
<input type="button" class="btn btn-primary" id="accept_all" value="Accept All">
52+
<input type="button" class="btn btn-warning" value="Mark as Resolved">
53+
</div>
54+
</form>
55+
56+
</div>
57+
@stop
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@extends('layouts.default')
2+
@section('content')
3+
<div class="suggestion-list">
4+
<div class="text-center">
5+
<h1><a href="/location/management/my-locations">Suggestions for {{ $name }}</a></h1>
6+
</div>
7+
@if ( count($suggestions) === 0 )
8+
<p class="text-center">There is no suggestions about this location.</p>
9+
@else
10+
<div class="list-group">
11+
@foreach($suggestions as $suggestion)
12+
<a href="/suggestion-detail/{{ $suggestion->id }}" class="list-group-item" title="Click to check details">
13+
<span class="username">Submitted by: {{ $suggestion->user_name }}</span>
14+
<span class="when_generated">{{ $suggestion->when_generated }}</span>
15+
</a>
16+
@endforeach
17+
</div>
18+
@endif
19+
20+
</div>
21+
@stop

app/routes/location.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@
2424
Route::get('location-reporting/{location_id}/{question_category_id}', 'LocationReportController@show2');
2525
Route::post('api/set-search-radius', 'LocationSearchController@setSearchRadius');
2626
Route::post('api/add-suggestion', 'SuggestionController@addSuggestion');
27+
Route::get('suggestion-list/{location_id}', 'SuggestionController@showSuggestionList');
28+
Route::get('suggestion-detail/{suggestion_id}', 'SuggestionController@showSuggestionDetail');
2729
Route::get('location/management/edit/{location_id}', 'LocationManagementController@editLocation');
2830
Route::post('location/management/edit', 'LocationManagementController@editLocationSave');

0 commit comments

Comments
 (0)