Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Acl/EsiRolesMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ class EsiRolesMap
'corporation.summary',
'corporation.market',
],
'Project Manager' => [
'corporation.projects',
],
];

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Config/Permissions/corporation.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,8 @@
'label' => 'web::permissions.corporation_tracking_label',
'description' => 'web::permissions.corporation_tracking_description',
],
'projects' => [
'label' => 'web::permissions.corporation_projects_label',
'description' => 'web::permissions.corporation_projects_description',
],
];
8 changes: 8 additions & 0 deletions src/Config/package.corporation.menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
'highlight_view' => 'industry',
'route' => 'seatcore::corporation.view.industry',
],
[
'name' => 'project',
'label' => 'web::seat.project',
'plural' => true,
'permission' => 'corporation.projects',
'highlight_view' => 'projects',
'route' => 'seatcore::corporation.view.projects',
],
[
'name' => 'killmails',
'label' => 'web::seat.killmails',
Expand Down
1 change: 1 addition & 0 deletions src/Config/web.jobnames.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
'transactions' => \Seat\Eveapi\Jobs\Wallet\Corporation\Transactions::class,
'starbases' => \Seat\Eveapi\Jobs\Corporation\Starbases::class,
'structures' => \Seat\Eveapi\Jobs\Corporation\Structures::class,
'projects' => \Seat\Eveapi\Jobs\CorporationProjects\Projects::class,
],
'alliance' => [
'contacts' => [
Expand Down
169 changes: 169 additions & 0 deletions src/Http/Controllers/Corporation/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Http\Controllers\Corporation;

use Seat\Eveapi\Models\Corporation\CorporationInfo;
use Seat\Eveapi\Models\CorporationProjects\CorporationProject;
use Seat\Web\Http\Controllers\Controller;
use Seat\Web\Http\DataTables\Corporation\Financial\ProjectDataTable;
use Seat\Web\Http\DataTables\Scopes\CorporationScope;

/**
* Class StructureController.
*
* @package Seat\Web\Http\Controllers\Corporation
*/
class ProjectController extends Controller
{
/**
* @param \Seat\Eveapi\Models\Corporation\CorporationInfo $corporation
* @param \Seat\Web\Http\DataTables\Corporation\Military\StructureDataTable $dataTable
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getProjects(CorporationInfo $corporation, ProjectDataTable $dataTable)
{

return $dataTable->addScope(new CorporationScope('corporation.projects', [$corporation->corporation_id]))
->render('web::corporation.projects.list', compact('corporation'));
}

/**
* @param \Seat\Eveapi\Models\Corporation\CorporationInfo $corporation
* @param string $project_id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getProject(CorporationInfo $corporation, string $project_id)
{
$project = CorporationProject::with('contributors', 'creator')
->where('id', $project_id)
->first();
$config = $this->normalizeProjectConfiguration($project->configuration);

return view('web::corporation.projects.modals.content', compact('corporation', 'project', 'config'));
}

/**
* Normalize project configuration into an array of items:
* [ ['key'=>'...', 'label'=>'...', 'value'=>'...', 'description'=>null], ... ]
*/
protected function normalizeProjectConfiguration($configuration): array
{
if (is_string($configuration)) {
// sometimes stored as JSON string
$decoded = json_decode($configuration, true);
if (json_last_error() === JSON_ERROR_NONE) {
$configuration = $decoded;
}
}

// If null or empty
if (empty($configuration)) {
return [];
}

$items = [];

// Case: configuration is an array of option objects
if (is_array($configuration) && array_values($configuration) === $configuration) {
foreach ($configuration as $i => $opt) {
if (is_array($opt)) {
$items[] = [
'key' => $opt['name'] ?? "option_{$i}",
'label' => $opt['display_name'] ?? $opt['name'] ?? "Option {$i}",
'value' => isset($opt['value']) ? $opt['value'] : (isset($opt['default']) ? $opt['default'] : null),
'description' => $opt['description'] ?? null,
];
} else {
// primitive in array
$items[] = [
'key' => "option_{$i}",
'label' => "Option {$i}",
'value' => (string) $opt,
'description' => null,
];
}
}

return $items;
}

// Case: configuration is an associative object/array of named options
if (is_array($configuration)) {
foreach ($configuration as $k => $v) {
if (is_array($v) || is_object($v)) {
$vArr = (array) $v;
$items[] = [
'key' => $k,
'label' => $vArr['label'] ?? $vArr['name'] ?? $k,
'value' => $vArr['value'] ?? $vArr['default'] ?? json_encode($vArr),
'description' => $vArr['description'] ?? null,
];
} else {
$items[] = [
'key' => $k,
'label' => $k,
'value' => $v,
'description' => null,
];
}
}

return $items;
}

// Case: object (stdClass)
if (is_object($configuration)) {
$arr = (array) $configuration;
foreach ($arr as $k => $v) {
if (is_object($v) || is_array($v)) {
$vArr = (array) $v;
$items[] = [
'key' => $k,
'label' => $vArr['label'] ?? $vArr['name'] ?? $k,
'value' => $vArr['value'] ?? $vArr['default'] ?? json_encode($vArr),
'description' => $vArr['description'] ?? null,
];
} else {
$items[] = [
'key' => $k,
'label' => $k,
'value' => $v,
'description' => null,
];
}
}

return $items;
}

// Fallback: stringify whatever it is
return [
[
'key' => 'raw',
'label' => 'Configuration',
'value' => is_scalar($configuration) ? (string) $configuration : json_encode($configuration),
'description' => null,
],
];
}
}
117 changes: 117 additions & 0 deletions src/Http/DataTables/Corporation/Financial/ProjectDataTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/*
* This file is part of SeAT
*
* Copyright (C) 2015 to present Leon Jacobs
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

namespace Seat\Web\Http\DataTables\Corporation\Financial;

use Illuminate\Http\JsonResponse;
use Seat\Eveapi\Models\CorporationProjects\CorporationProject;
use Yajra\DataTables\Services\DataTable;

/**
* Class StructureDataTable.
*
* @package Seat\Web\Http\DataTables\Corporation\Financial
*/
class ProjectDataTable extends DataTable
{
/**
* @return \Illuminate\Http\JsonResponse
*
* @throws \Exception
*/
public function ajax(): JsonResponse
{
return datatables()
->eloquent($this->applyScopes($this->query()))
->editColumn('state', function ($row) {
return ucfirst(str_replace('_', ' ', $row->state));
})
->addColumn('progress', function ($raw) {
$row = (object) [
'min' => 0,
'value' => $raw->progress_current,
'max' => $raw->progress_desired,
'showval' => true,
];

return view('web::partials.progress', compact('row'))->render();
})
->addColumn('reward', function ($raw) use (&$rawColumns) {
if (is_null($raw->reward_initial) || $raw->reward_initial == 0) {
return trans('web::seat.no_reward');
} else {
$row = (object) [
'min' => 0,
'value' => $raw->reward_initial - $raw->reward_remaining,
'max' => $raw->reward_initial,
'showval' => true,
];
$rawColumns[] = 'reward';

return view('web::partials.progress', compact('row'))->render();
}
})
->editColumn('action', function ($row) use ($rawColumns) {
return view('web::corporation.projects.buttons.action', compact('row'))->render();
})
->rawColumns(['action', 'progress', 'reward'])
->toJson();
}

/**
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->postAjax()
->columns($this->getColumns())
->addAction()
->addTableClass('table-striped table-hover')
->parameters([
'drawCallback' => 'function() { $("[data-toggle=tooltip]").tooltip(); }',
]);
}

/**
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query()
{
return CorporationProject::withCount('contributors');
}

/**
* @return array
*/
public function getColumns()
{
return [
['data' => 'name', 'title' => trans_choice('web::seat.name', 1)],
['data' => 'last_modified', 'title' => trans_choice('web::seat.last_modified', 1)],
['data' => 'state', 'title' => trans('web::seat.state')],
['data' => 'progress', 'title' => trans('web::seat.progress'), 'orderable' => false],
['data' => 'reward', 'title' => trans('web::seat.reward'), 'orderable' => false],
['data' => 'contributors_count', 'title' => trans_choice('web::seat.contributor', 2)],
Comment thread
Crypta-Eve marked this conversation as resolved.
];
}
}
10 changes: 10 additions & 0 deletions src/Http/Routes/Corporation/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,13 @@
Route::post('/{corporation}/transactions/export')
->uses('WalletController@transactions')
->middleware('can:corporation.transaction,corporation');

Route::get('/{corporation}/projects')
->name('seatcore::corporation.view.projects')
->uses('ProjectController@getProjects')
->middleware('can:corporation.projects,corporation');

Route::get('/{corporation}/project/{project_id}')
->name('seatcore::corporation.view.projects.details')
->uses('ProjectController@getProject')
->middleware('can:corporation.projects,corporation');
1 change: 1 addition & 0 deletions src/WebServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ private function register_settings()
'esi-universe.read_structures.v1',
'esi-wallet.read_character_wallet.v1',
'esi-wallet.read_corporation_wallets.v1',
'esi-corporations.read_projects.v1',
],
],
]);
Expand Down
Loading