Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
170 changes: 170 additions & 0 deletions src/Http/Controllers/Corporation/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?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 uuid $project_id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getProject(CorporationInfo $corporation, $project_id)
{
$project = CorporationProject::with('contributors', 'creator')
->where('id', $project_id)
->first();
$config = $this->normalizeProjectConfiguration($project->configuration);

// dd($project, $corporation);
Comment thread
Crypta-Eve marked this conversation as resolved.
Outdated
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 'No Reward'; // TODO localise
Comment thread
Crypta-Eve marked this conversation as resolved.
Outdated
} 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')],
['data' => 'reward', 'title' => trans('web::seat.reward')],
['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
6 changes: 6 additions & 0 deletions src/resources/lang/en/seat.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@
'tracking' => 'Tracking',
'about' => 'About',
'market_browser' => 'Market Browser',
'project' => 'Project|Projects',
'last_modified' => 'Last Modified',

'assets' => 'Assets',
'location_flag' => 'Location Flag',
Expand Down Expand Up @@ -496,6 +498,7 @@
'update_transactions' => 'Update Transactions',
'update_wallet' => 'Update Wallet',
'update_loyalty_points' => 'Update Loyalty Points',
'update_projects' => 'Update Projects',

// Character
'joined_curr_corp' => 'Joined Current Corporation',
Expand Down Expand Up @@ -770,4 +773,7 @@
'sde_version' => 'SDE Version',
'render_in' => 'Rendered In',
'copyright' => 'Copyright',

// Projects
'contributor' => 'Contributor|Contributors',
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- TBD if more buttons required -->
@include('web::corporation.projects.buttons.details')
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<button data-toggle="modal" data-target="#project-detail" class="btn btn-sm btn-link"
data-url="{{ route('seatcore::corporation.view.projects.details', ['corporation' => $row->corporation_id, 'project_id' => $row->id]) }}">
<i class="fa fa-wrench"></i>
</button>
Loading