Skip to content

Commit

Permalink
Merge pull request #91 from simde-utc/develop
Browse files Browse the repository at this point in the history
Stabilisation générale du portail avec amélioration de l'affichage
  • Loading branch information
NastuzziSamy authored Feb 23, 2019
2 parents ac8a5d8 + 4f4aaf5 commit e6d6099
Show file tree
Hide file tree
Showing 144 changed files with 21,756 additions and 7,801 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ OLD_DB_PASSWORD=portail-old

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=redis
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
Expand Down
6 changes: 3 additions & 3 deletions .env.travis
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ APP_NAME="Portail des Assos"
APP_ENV=develop
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://localhost:8000
APP_ASSO=simde

LOG_CHANNEL=stack
Expand All @@ -16,9 +16,9 @@ DB_PASSWORD=""

BROADCAST_DRIVER=log
CACHE_DRIVER=redis
SESSION_DRIVER=database
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=redis
QUEUE_DRIVER=database

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/*
97 changes: 97 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"parser": "babel-eslint",
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": ["node_modules", "src/"]
}
}
},

"plugins": [
"react",
"react-redux",
"jsx",
"prettier"
],

"globals": {
"document": true,
"window": true,
"React": true,
"ReactDOM": true,
"process": true,
"module": true,
"axios": true,
"_": true
},

"env": {
"es6": true,
"node": true,
"browser": true,
"jest": true
},

"extends": [
"airbnb",
"prettier",
"plugin:react/recommended",
"plugin:react-redux/recommended",
"prettier/babel",
"prettier/react"
],

"rules": {
"camelcase": 0,
"linebreak-style": [2, "unix"],
"semi": [1, "always"],
"indent": [0, "tab"],
"no-console": 0,
"no-case-declarations": 1,
"no-fallthrough": 0,
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-unused-vars": [1,
{ "vars": "local",
"argsIgnorePattern": "^_",
"args": "after-used"
}],
"comma-dangle": [1, "always-multiline"],
"no-cond-assign": 1,
"no-case-declarations": 0,
"no-restricted-syntax": 0,
"no-prototype-builtins": 0,
"no-shadow": 0,
"no-param-reassign": 0,
"guard-for-in": 0,
"react/jsx-no-undef": 2,
"react/jsx-uses-react": 2,
"react/jsx-filename-extension": 0,
"react/jsx-uses-vars": 2,
"react/no-did-mount-set-state": 2,
"react/no-did-update-set-state": 2,
"react/no-multi-comp": 0,
"react/no-unknown-property": 2,
"react/prop-types": 0,
"react/react-in-jsx-scope": 2,
"react/self-closing-comp": 2,
"react-redux/connect-prefer-named-arguments": 0,
"react-redux/mapStateToProps-prefer-parameters-names": 0,
"react/jsx-wrap-multilines": ["error", {
"declaration": true,
"assignment": true,
"return": true,
"arrow": true
}],
"react/jsx-no-bind": 0,
"react/jsx-no-target-blank": 2,
"react/no-unescaped-entities": ["error", {"forbid": [">", "}", "\""]}],
"prettier/prettier": ["error"],
"no-unused-expressions": 0,
"jsx-a11y/click-events-have-key-events": 0,
"jsx-a11y/no-static-element-interactions": 0,
"jsx-a11y/anchor-is-valid": 0,
"jsx-a11y/label-has-associated-control": 0,
"jsx-a11y/label-has-for": 0
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ public/css/bootstrap\.css
public/js/index\.js
public/docs/*
public/mix-manifest\.json
public/images/articles/*
public/images/assos/*
public/images/events/*
public/images/services/*
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 100,
"singleQuote": true,
"useTabs": true,
"trailingComma": "es5"
}
2 changes: 1 addition & 1 deletion app/Admin/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function getLogin()
if (($user = \Auth::guard('web')->user())->getUserPermissions()->count()) {
$this->guard()->login(Admin::find($user->getKey()));

return redirect(config('admin.route.prefix'));
return redirect(redirect()->intended()->getTargetUrl() ?: config('admin.route.prefix'));
} else {
return redirect('/');
}
Expand Down
161 changes: 155 additions & 6 deletions app/Admin/Controllers/ChartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

namespace App\Admin\Controllers;

use DB;
use Carbon\Carbon;
use App\Http\Controllers\Controller;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Box;
use App\Models\User;
use App\Models\{
User, AuthCas, AuthPassword, AuthApp, Semester
};

class ChartsController extends Controller
{
Expand All @@ -25,15 +29,160 @@ class ChartsController extends Controller
*/
public function index(Content $content)
{
$dates = [];
return $content
->header('Charts')
->body(new Box('Utilisateurs', view('admin.charts.users', $this->getUserData())))
->body(new Box('Membres des associations', view('admin.charts.assos_members', $this->getMemberData())));
}

/**
* Récupère les données utilisateurs.
*
* @return array
*/
protected function getUserData(): array
{
$users = [];
$usersBar = [];
$nbr = 0;

foreach (User::orderBy('created_at')->get(['created_at']) as $user) {
$dates[$user->created_at->format('d-m-Y H:m:s')] = ++$nbr;
$date = $user->created_at->format('d/m/Y');
$users[$date] = ++$nbr;

if (isset($usersBar[$date])) {
$usersBar[$date]++;
} else {
$usersBar[$date] = 1;
}
}

return $content
->header('Charts')
->body(new Box('Utilisateurs', view('admin.charts.users', ['data' => $dates])));
return [
'users' => $users,
'usersBar' => $usersBar,
'auths' => [
'CAS-UTC' => AuthCas::count(),
'Email/Mot de passe' => AuthPassword::count(),
'Application' => AuthApp::count()
]
];
}

/**
* Récupère les membres utilisateurs.
*
* @return array
*/
protected function getMemberData()
{
$semesters = Semester::get();
$memberList = DB::select('SELECT created_at FROM assos_members WHERE role_id is not NULL ORDER BY created_at');
$uniqueMemberList = DB::select('SELECT count(asso_id) as assos, created_at FROM assos_members WHERE role_id is not
NULL GROUP BY user_id, semester_id ORDER BY created_at');
$members = [];
$membersByDay = [];
$membersByMonth = [];
$membersBySemester = [];
$nbr = 0;

foreach ($memberList as $member) {
$date = (new Carbon($member->created_at))->format('d/m/Y');
$members[$date] = ++$nbr;
$membersByDay[$date] = (($membersByDay[$date] ?? 0) + 1);

$date = (new Carbon($member->created_at))->format('m/Y');
$membersByMonth[$date] = (($membersByMonth[$date] ?? 0) + 1);

foreach ($semesters as $semester) {
if ($member->created_at >= $semester->begin_at && $member->created_at <= $semester->end_at) {
$membersBySemester[$semester->name] = (($membersBySemester[$semester->name] ?? 0) + 1);
break;
}
}
}

$uMembers = [];
$uMembersByDay = [];
$uMembersByMonth = [];
$uMembersBySemester = [];
$assosPerMemberKeys = [];
$assosPerMemberValues = [];
$nbr = 0;

foreach ($uniqueMemberList as $member) {
$date = (new Carbon($member->created_at))->format('d/m/Y');
$uMembers[$date] = ++$nbr;
$uMembersByDay[$date] = (($uMembersByDay[$date] ?? 0) + 1);

$date = (new Carbon($member->created_at))->format('m/Y');
$uMembersByMonth[$date] = (($uMembersByMonth[$date] ?? 0) + 1);

foreach ($semesters as $semester) {
if ($member->created_at >= $semester->begin_at && $member->created_at <= $semester->end_at) {
$uMembersBySemester[$semester->name] = (($uMembersBySemester[$semester->name] ?? 0) + 1);

if (isset($assosPerMemberValues[$semester->name])) {
$assosPerMemberValues[$semester->name][$member->assos] = (
($assosPerMemberValues[$semester->name][$member->assos] ?? 0) + 1
);
} else {
$assosPerMemberValues[$semester->name] = [$member->assos => 1];
}

break;
}
}

$assosPerMemberKeys[$member->assos] = true;
}

foreach ($assosPerMemberValues as $semesterName => $assosPerMemberValue) {
$assosPerMemberValues[$semesterName] = $this->adjustKeysWith0($assosPerMemberKeys, $assosPerMemberValue);
}

$uMembers = $this->adjustKeys($members, $uMembers);
$uMembersByDay = $this->adjustKeys($membersByDay, $uMembersByDay);
$uMembersByMonth = $this->adjustKeys($membersByMonth, $uMembersByMonth);
$uMembersBySemester = $this->adjustKeys($membersBySemester, $uMembersBySemester);

return compact('members', 'membersByDay', 'membersByMonth', 'membersBySemester', 'uMembers',
'uMembersByDay', 'uMembersByMonth', 'uMembersBySemester', 'assosPerMemberKeys', 'assosPerMemberValues');
}

/**
* Adjuste les tableaux pour avoir les même clés.
*
* @param array $reference
* @param array $data
* @return array
*/
protected function adjustKeys(array $reference, array $data)
{
$lastValue = 0;
$newData = [];

foreach (array_keys($reference) as $key) {
$lastValue = ($newData[$key] = ($data[$key] ?? $lastValue));
}

return $newData;
}

/**
* Adjuste les tableaux pour avoir les même clés en assigant 0.
*
* @param array $reference
* @param array $data
* @return array
*/
protected function adjustKeysWith0(array $reference, array $data)
{
$newData = [];

foreach (array_keys($reference) as $key) {
$newData[$key] = ($data[$key] ?? 0);
}

return $newData;
}
}
1 change: 1 addition & 0 deletions app/Admin/Controllers/Resource/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function getFields(): array
'secret' => 'text',
'redirect' => 'text',
'targeted_types' => 'text',
'policy_url' => 'text',
'personal_access_client' => 'switch',
'password_client' => 'switch',
'created_at' => 'display',
Expand Down
Loading

0 comments on commit e6d6099

Please sign in to comment.