Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf56cdd

Browse files
committed
Merge remote-tracking branch 'origin'
2 parents ddf1c22 + 0eeaf4f commit cf56cdd

File tree

65 files changed

+37363
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+37363
-168
lines changed

app/assets/javascripts/application.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
//= require turbolinks
44
//= require popper
55
//= require bootstrap
6+
//= require_tree ./scoped/.
7+
//= require_tree ./core/.
68
//= require_tree .

app/assets/javascripts/core/global.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,28 @@ alerts = function() {
2020

2121
// Allow the user to jump to a specific page
2222
pageJump = function() {
23-
$('.input-group-btn').click(function() {
24-
var link = $('.input-group-btn a');
23+
$('.page-jump-btn').click(function() {
24+
var link = $('.page-jump-btn a');
2525
var input = $('.page-jump');
26-
if(input.val() != '') {
26+
var re = /^[0-9]+$/;
27+
if(re.test(input.val())) {
2728
link.attr('href', link.attr('href') + '?page=' + input.val());
2829
}
30+
else {
31+
link.attr('href', link.attr('href') + '?page=*');
32+
}
2933
});
34+
}
35+
36+
// Enable buttons that rely on javascript to function/remove warning text
37+
enableButtons = function() {
38+
if($('.page-jump-btn')) {
39+
$('.page-jump-btn a').removeClass('disabled');
40+
}
41+
if($('.tag-search-btn')) {
42+
$('.tag-search-btn a').removeClass('disabled');
43+
}
44+
if($('.js-text')) {
45+
$('.js-text').remove();
46+
}
3047
}

app/assets/javascripts/core/init.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ init = function() {
22
// Persistant functions
33
alerts();
44
pageJump();
5+
enableButtons();
56

67
// Scoped functions
78
makeCaretsDynamic();
89
initMaps();
910
preventFontInjection();
11+
tagSearch();
1012
rentalHeaderColor();
1113
};
1214

app/assets/javascripts/scoped/rentals.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ initMaps = function() {
2121
else {
2222
$('#map-start').remove();
2323
$('#start-col').addClass('no-section-content');
24-
$('#start-col').append('<div class="text-center font-italic d-flex align-items-center"><div><p>The Start Location could not be found:</p><p>'+
25-
$('#start-location').text()+'</p></div></div>');
24+
$('#start-col').append('<div class="no-map"><div><p>Looks like the Start Location could not be found...</p></div></div>');
2625
}
2726
if(!isNaN(end_location.lat()) && !isNaN(end_location.lng())) {
2827
new google.maps.Marker({
@@ -36,8 +35,7 @@ initMaps = function() {
3635
else {
3736
$('#map-end').remove();
3837
$('#end-col').addClass('no-section-content');
39-
$('#end-col').append('<div class="text-center font-italic d-flex align-items-center"><div><p>The End Location could not be found:</p><p>'+
40-
$('#end-location').text()+'</p></div></div>');
38+
$('#end-col').append('<div class="no-map"><div><p>Looks like the End Location could not be found...</p></div></div>');
4139
}
4240
}
4341

@@ -57,6 +55,21 @@ preventFontInjection = function() {
5755
};
5856
}
5957

58+
// Allow the user to search available rentals for a specific tag
59+
tagSearch = function() {
60+
$('.tag-search-btn').click(function() {
61+
var link = $('.tag-search-btn a');
62+
var input = $('.tag-search');
63+
var re = /^[a-zA-Z0-9\s\-]+$/;
64+
if(re.test(input.val())) {
65+
link.attr('href', link.attr('href') + '?tag=' + input.val());
66+
}
67+
else {
68+
link.attr('href', link.attr('href') + '?tag=*');
69+
}
70+
});
71+
}
72+
6073
// Randomize rental card header gradient angle
6174
rentalHeaderColor = function() {
6275
if($('#users-overview').length == 0 &&

app/assets/stylesheets/core/global.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ a.disabled {
351351
border: 2px solid black;
352352
}
353353

354+
.page-jump {
355+
min-width: 60%;
356+
}
357+
354358
.account-access-link {
355359
display: block;
356360
margin-top: $spacer * 0.5;

app/assets/stylesheets/partials/_rentals.scss

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
margin-left: $spacer * 0.5;
33
}
44

5+
#start-col,
6+
#end-col {
7+
.card-body {
8+
p {
9+
margin-bottom: ($spacer * 0.25);
10+
}
11+
}
12+
}
13+
514
#map-start,
615
#map-end {
716
display: block;
@@ -15,15 +24,18 @@
1524
.no-section-content {
1625
display: flex;
1726
flex-direction: column;
18-
height: 40vh;
1927

2028
hr {
2129
margin-top: 0.25rem;
22-
margin-bottom: 0;
2330
}
2431

25-
div {
32+
.no-map {
33+
margin-top: ($spacer * 4);
34+
display: flex;
2635
flex-grow: 1;
36+
align-items: center;
37+
text-align: center;
38+
font-style: italic;
2739

2840
div {
2941
flex-grow: 1;

app/controllers/application_controller.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@ class ApplicationController < ActionController::Base
22
# protect_from_forgery with: :exception
33
include SessionsHelper
44

5-
def validate_page(page, total, per)
6-
page = page.to_s
5+
private
6+
7+
def valid_page?(page, total, per)
8+
valid = false
79
last = (total / per.to_f).ceil
8-
if page.match?(/\A\d+\z/)
10+
if page.match(/\A\d+\z/)
911
page = page.to_i
10-
if page < 1
11-
page = 1
12-
elsif page > last
13-
page = last
12+
if page < 1 || page > last
13+
message = 'The page you tried to jump to does not exist'
14+
else
15+
valid = true
1416
end
1517
else
16-
page = 1
18+
message = 'The page you tried to jump to contained invalid characters'
19+
end
20+
if !valid
21+
page = nil
1722
end
1823

19-
return page
24+
return page, valid, message
2025
end
2126

22-
private
23-
2427
# Confirms the user is a guest
2528
def guest_user
2629
if signed_in?

app/controllers/cars_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
class CarsController < ApplicationController
22
before_action :signed_in_user
3-
before_action :correct_user, except: [:new, :create]
3+
before_action :correct_user, except: [:new, :create, :tag_search]
44
before_action :set_car, only: [:edit, :update, :destroy]
55

66
# GET /cars/new
@@ -99,14 +99,6 @@ def destroy
9999
end
100100
end
101101

102-
def tag_search
103-
if params[:tag]
104-
@cars = Car.tagged_with(params[:tag])
105-
else
106-
@cars = Car.all
107-
end
108-
end
109-
110102
private
111103

112104
# Never trust parameters from the scary internet, only allow the white list through.

0 commit comments

Comments
 (0)