Skip to content

Commit

Permalink
Merge pull request cydrobolt#170 from cydrobolt/enhancement/API_ui_admin
Browse files Browse the repository at this point in the history
Enhancement/api ui admin
  • Loading branch information
cydrobolt committed Apr 16, 2016
2 parents 985dd4e + 7ec83f5 commit f426dea
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/Factories/LinkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function createLink($long_url, $is_secret=false, $custom_ending=nu
looks like a shortened URL.');
}

if (!$is_secret && !$custom_ending && $existing_link = LinkHelper::longLinkExists($long_url)) {
if (!$is_secret && !$custom_ending && ($existing_link = LinkHelper::longLinkExists($long_url)) !== false) {
// if link is not specified as secret, is non-custom, and
// already exists in Polr, lookup the value and return
return self::formatLink($existing_link);
Expand Down
12 changes: 11 additions & 1 deletion app/Helpers/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ public static function checkUserApiQuota($username) {

$user = UserHelper::getUserByUsername($username);

if ($user) {
$api_quota = $user->api_quota;
}
else {
// TODO add option to change default quota for anonymous
// API users

$api_quota = 5;
}

$links_last_minute = Link::where('is_api', 1)
->where('creator', $username)
->where('created_at', '>=', $last_minute)
->count();

return ($links_last_minute >= $user->api_quota);
return ($api_quota > -1 && $links_last_minute >= $api_quota);
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AdminController extends Controller {
*/
public function displayAdminPage(Request $request) {
if (!$this->isLoggedIn()) {
return abort(404);
return redirect(route('login'))->with('error', 'Please login to access your dashboard.');
}

$username = session('username');
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Api/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ protected static function getApiUserInfo(Request $request) {

if (!$api_key) {
// no API key provided -- check whether anonymous API is on
// TODO: throttle requests from anonymous API

if (env('SETTING_ANON_API') == 'on') {
$username = 'ANONIP-' . $request->ip();
}
Expand Down
10 changes: 10 additions & 0 deletions public/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@
.api-quota {
display: inline;
}

.wrap-text {
word-wrap: break-word;
}

@media (min-width: 700px) {
table {
table-layout: fixed;
}
}
15 changes: 12 additions & 3 deletions public/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ body {
margin-bottom: 15px;
}

.content-div-padding {
padding-top: 65px;
}
.content-div {
text-align: left;
background-color: rgba(0,0,0,0);
Expand All @@ -40,3 +37,15 @@ body {
.error-alert {
text-align: left;
}

@media (min-width: 768px) {
.content-div-padding {
padding-top: 4em;
}
}

@media (max-width: 768px) {
.content-div-padding {
padding-top: 1em;
}
}
4 changes: 2 additions & 2 deletions resources/views/admin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@endsection

@section('content')
<div class='col-md-3'>
<div class='col-md-2'>
<ul class='nav nav-pills nav-stacked admin-nav' role='tablist'>
<li role='presentation' aria-controls="home" class='admin-nav-item active'><a href='#home'>Home</a></li>
<li role='presentation' aria-controls="links" class='admin-nav-item'><a href='#links'>Links</a></li>
Expand All @@ -20,7 +20,7 @@
@endif
</ul>
</div>
<div class='col-md-9'>
<div class='col-md-10'>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">
<h2>Welcome to your {{env('APP_NAME')}} dashboard!</h2>
Expand Down
9 changes: 6 additions & 3 deletions resources/views/snippets/link_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
@foreach ($links as $link)
<tr>
<td>{{$link->short_url}}</td>
{{-- TODO truncate long link --}}
<td>{{$link->long_url}}</td>
<td class='wrap-text'>
<a href='{{$link->long_url}}'>
{{str_limit($link->long_url, 50, '...')}}
</a>
</td>
<td>{{$link->clicks}}</td>
<td>{{$link->created_at}}</td>
<td>{{isset($link->secret_key)}}</td>
<td>{{empty($link->secret_key) ? 'false' : 'true'}}</td>

@if ($role == 'admin')
<td>{{$link->creator}}</td>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/snippets/user_table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<td>{{$user->username}}</td>
<td>{{$user->email}}</td>
<td>{{$user->created_at}}</td>
<td>{{$user->active}}</td>
<td>{{$user->active ? 'true' : 'false'}}</td>
<td>
@if ($user->active)
<a class='activate-api-modal btn btn-sm btn-info'
Expand Down

0 comments on commit f426dea

Please sign in to comment.