forked from johndavedecano/laragym
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c0f988
commit 845d5f3
Showing
31 changed files
with
884 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Dave | ||
* Date: 9/13/2018 | ||
* Time: 11:21 PM | ||
*/ | ||
|
||
namespace App\Http\Controllers; | ||
|
||
|
||
use App\CacheKey; | ||
use App\Models\Package; | ||
use App\Models\Service; | ||
use App\Models\Subscription; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Cache; | ||
|
||
class StatisticsController extends Controller | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function services() | ||
{ | ||
$count = Cache::remember(CacheKey::get(), 15, function() { | ||
return Service::where('status', 'active')->count(); | ||
}); | ||
|
||
return response()->json($count); | ||
} | ||
|
||
public function packages() | ||
{ | ||
$count = Cache::remember(CacheKey::get(), 15, function() { | ||
return Package::where('status', 'active')->count(); | ||
}); | ||
|
||
return response()->json($count); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function members() | ||
{ | ||
$count = Cache::remember(CacheKey::get(), 15, function() { | ||
return User::where('is_admin', false)->count(); | ||
}); | ||
|
||
return response()->json($count); | ||
} | ||
|
||
/** | ||
* @return \Illuminate\Http\JsonResponse | ||
*/ | ||
public function subscriptions() | ||
{ | ||
$count = Cache::remember(CacheKey::get(), 15, function() { | ||
return Subscription::where('status', 'active')->count(); | ||
}); | ||
|
||
return response()->json($count); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
resources/apps/frontend/src/components/Form/Select/MemberSelect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from 'react'; | ||
import AsyncSelect from 'react-select/lib/Async'; | ||
import Select from 'react-select'; | ||
|
||
import {loadMembers, showMember} from 'requests/members'; | ||
|
||
export default class MemberSelect extends React.Component { | ||
state = { | ||
defaultValue: null, | ||
defaultOptions: [], | ||
}; | ||
|
||
static defaultProps = { | ||
name: 'user_id', | ||
onChange: () => {}, | ||
}; | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
|
||
if (this.props.defaultValue) { | ||
this.loadInitialOption(this.props.defaultValue); | ||
} | ||
} | ||
|
||
loadInitialOption = async id => { | ||
try { | ||
this.setState({isInitializing: true}); | ||
|
||
const response = await showMember(id); | ||
|
||
if (!this._isMounted) return; | ||
|
||
this.setState({ | ||
defaultValue: response.data, | ||
defaultOptions: [response.data], | ||
isInitializing: false, | ||
}); | ||
} catch (error) { | ||
this.setState({isInitializing: false}); | ||
return; | ||
} | ||
}; | ||
|
||
loadOptions = async q => { | ||
try { | ||
const response = await loadMembers({q, limit: 10}); | ||
return response.data; | ||
} catch (err) { | ||
return []; | ||
} | ||
}; | ||
|
||
render() { | ||
if (this.state.isInitializing) return <Select isLoading />; | ||
return ( | ||
<AsyncSelect | ||
options={this.state.defaultOptions} | ||
name={this.props.name} | ||
defaultValue={this.state.defaultValue} | ||
getOptionLabel={option => option.name} | ||
getOptionValue={option => option.id} | ||
cacheOptions={true} | ||
defaultOptions | ||
loadOptions={this.loadOptions} | ||
onChange={this.props.onChange} | ||
/> | ||
); | ||
} | ||
} |
Oops, something went wrong.