Skip to content

Commit

Permalink
Merge pull request #5 from warlof/setting-and-seeds
Browse files Browse the repository at this point in the history
drop setting table and use core setting helper instead
  • Loading branch information
BenH authored Dec 13, 2017
2 parents ec5abda + 85e944a commit 737d08d
Show file tree
Hide file tree
Showing 39 changed files with 277 additions and 152 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"type": "seat-plugin",
"autoload": {
"psr-4": {
"Seat\\Kassie\\Calendar\\": "src/"
"Seat\\Kassie\\Calendar\\": "src/",
"Seat\\Kassie\\Calendar\\database\\seeds\\": "src/database/seeds/"
}
},
"require": {
Expand Down
11 changes: 3 additions & 8 deletions src/Commands/RemindOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,14 @@ public function __construct()

public function handle()
{
if (Settings::get('slack_integration') == 1)
{
if (setting('kassie.calendar.slack_integration', true) == 1) {
$ops = Operation::all()->take(-50);
$now = Carbon::now('UTC');

foreach($ops as $op)
{
if ($op->status == 'incoming') {
if(in_array($now->diffInMinutes($op->start_at, false), $this->marks))
{
Notification::send($op, new OperationPinged());
}
}
if ($op->status == 'incoming' && in_array($now->diffInMinutes($op->start_at, false), $this->marks))
Notification::send($op, new OperationPinged());
}
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use Seat\Eveapi\Models\Account\ApiKeyInfoCharacters;

use Seat\Kassie\Calendar\Helpers\Settings;

class Helper
{
Expand Down Expand Up @@ -43,9 +42,15 @@ public static function BuildSlackNotificationAttachment($op) {
$fields = array();

$fields[trans('calendar::seat.starts_at')] = $op->start_at->format('F j @ H:i EVE');
$fields[trans('calendar::seat.duration')] = $op->getDurationAttribute() ? $op->getDurationAttribute() : trans('calendar::seat.unknown');
$fields[trans('calendar::seat.duration')] = $op->getDurationAttribute() ?
$op->getDurationAttribute() : trans('calendar::seat.unknown');

$fields[trans('calendar::seat.importance')] = self::ImportanceAsEmoji($op->importance, Settings::get('slack_emoji_importance_full'), Settings::get('slack_emoji_importance_half'), Settings::get('slack_emoji_importance_empty'));
$fields[trans('calendar::seat.importance')] =
self::ImportanceAsEmoji(
$op->importance,
setting('kassie.calendar.slack_emoji_importance_full', true),
setting('kassie.calendar.slack_emoji_importance_half', true),
setting('kassie.calendar.slack_emoji_importance_empty', true));

$fields[trans('calendar::seat.fleet_commander')] = $op->fc ? $op->fc : trans('calendar::seat.unknown');

Expand All @@ -70,4 +75,4 @@ public static function GetUserMainCharacter($user_id) {
return null;
}

}
}
21 changes: 0 additions & 21 deletions src/Helpers/Settings.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Http/Controllers/OperationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public function index(Request $request)
}

return view('calendar::operation.index', [
'slack_integration' => Settings::get('slack_integration'),
'userCharacters' => $userCharacters,
'ops_all' => $ops,
'ops_incoming' => $ops_incoming,
Expand Down
41 changes: 26 additions & 15 deletions src/Http/Controllers/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,45 @@
use Illuminate\Http\Request;

use Seat\Web\Http\Controllers\Controller;
use Seat\Kassie\Calendar\Helpers\Settings;
use Seat\Kassie\Calendar\Models\Setting;
use Seat\Kassie\Calendar\Models\Tag;

class SettingController extends Controller
{
public function index() {
$settings = Setting::all()->first();
$tags = Tag::all();

return view('calendar::setting.index', [
'settings' => $settings,
'tags' => $tags
]);
}

public function updateSlack(Request $request)
{
$settings = Setting::all()->first();

$settings->slack_integration = $request->slack_integration == 1 ? 1 : 0;
$settings->slack_webhook = $request->slack_webhook;
$settings->slack_emoji_importance_full = $request->slack_emoji_importance_full;
$settings->slack_emoji_importance_half = $request->slack_emoji_importance_half;
$settings->slack_emoji_importance_empty = $request->slack_emoji_importance_empty;

$settings->save();
{
setting([
'kassie.calendar.slack_integration',
$request->slack_integration == 1 ? 1 : 0,
], true);

setting([
'kassie.calendar.slack_webhook',
$request->slack_webhook,
], true);

setting([
'kassie.calendar.slack_emoji_importance_full',
$request->slack_emoji_importance_full
], true);

setting([
'kassie.calendar.slack_emoji_importance_half',
$request->slack_emoji_importance_half
], true);

setting([
'kassie.calendar.slack_emoji_importance_empty',
$request->slack_emoji_importance_empty
], true);

return redirect()->back();
}
}
}
5 changes: 1 addition & 4 deletions src/Models/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

use Carbon\Carbon;
use \DateTime;

use Seat\Web\Models\User;
use Seat\Kassie\Calendar\Helpers\Settings;
use Seat\Kassie\Calendar\Models\Tag;

class Operation extends Model
{
Expand Down Expand Up @@ -142,6 +139,6 @@ public function getNotifyAttribute($value)

public function routeNotificationForSlack()
{
return Settings::get('slack_webhook');
return setting('kassie.calendar.slack_webhook', true);
}
}
21 changes: 0 additions & 21 deletions src/Models/Setting.php

This file was deleted.

8 changes: 3 additions & 5 deletions src/Observers/OperationObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
use Seat\Kassie\Calendar\Models\Operation;
use Seat\Kassie\Calendar\Notifications\OperationPosted;
use Seat\Kassie\Calendar\Notifications\OperationUpdated;
use Seat\Kassie\Calendar\Notifications\OperationDeleted;
use Seat\Kassie\Calendar\Notifications\OperationCancelled;
use Seat\Kassie\Calendar\Notifications\OperationActivated;
use Seat\Kassie\Calendar\Helpers\Settings;

class OperationObserver
{
public function created(Operation $operation)
{
if (Settings::get('slack_integration') == 1 && $operation->notify == true)
if (setting('kassie.calendar.slack_integration', true) == 1 && $operation->notify == true)
Notification::send($operation, new OperationPosted());
}

public function updating(Operation $new_operation)
{
if (Settings::get('slack_integration') == 1 && $new_operation->notify == true) {
if (setting('kassie.calendar.slack_integration', true) == 1 && $new_operation->notify == true) {
$old_operation = Operation::find($new_operation->id);
if ($old_operation->is_cancelled != $new_operation->is_cancelled) {
if ($new_operation->is_cancelled == true)
Expand All @@ -35,4 +33,4 @@ public function updating(Operation $new_operation)
}
}
}
}
}
127 changes: 127 additions & 0 deletions src/database/migrations/2017_11_26_110800_update_settings_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Expression;
use Illuminate\Database\QueryException;

class UpdateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (Schema::hasTable('calendar_settings')) {

$settings = DB::table('calendar_settings')->first();

if (Schema::hasColumn('calendar_settings', 'slack_integration')) {
setting([
'kassie.calendar.slack_integration',
$settings->slack_integration,
], true);
}

if (Schema::hasColumn('calendar_settings', 'slack_webhook')) {
setting([
'kassie.calendar.slack_webhook',
$settings->slack_webhook,
], true);
}

if (Schema::hasColumn('calendar_settings', 'slack_emoji_importance_full')) {
setting([
'kassie.calendar.slack_emoji_importance_full',
$settings->slack_emoji_importance_full,
], true);
}

if (Schema::hasColumn('calendar_settings', 'slack_emoji_importance_half')) {
setting([
'kassie.calendar.slack_emoji_importance_half',
$settings->slack_emoji_importance_half,
], true);
}

if (Schema::hasColumn('calendar_settings', 'slack_emoji_importance_empty')) {
setting([
'kassie.calendar.slack_emoji_importance_empty',
$settings->slack_emoji_importance_empty,
], true);
}

Schema::drop('calendar_settings');

}
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
if (!Schema::hasTable('calendar_settings')) {

Schema::create('calendar_settings', function (Blueprint $table) {
$table->increments('id');
$table->boolean('slack_integration');
$table->string('slack_webhook');
$table->string('slack_emoji_importance_full');
$table->string('slack_emoji_importance_half');
$table->string('slack_emoji_importance_empty');
});

}

if (!Schema::hasColumn('calendar_settings', 'slack_integration')) {
Schema::table('calendar_settings', function(Blueprint $table) {
$table->boolean('slack_integration')->first();
});
}

if (!Schema::hasColumn('calendar_settings', 'slack_webhook')) {
Schema::table('calendar_settings', function(Blueprint $table) {
$table->string('slack_webhook')->after('slack_integration');
});
}

if (!Schema::hasColumn('calendar_settings', 'slack_emoji_importance_full')) {
Schema::table('calendar_settings', function(Blueprint $table) {
$table->string('slack_emoji_importance_full')->after('slack_webhook');
});
}

if (!Schema::hasColumn('calendar_settings', 'slack_emoji_importance_half')) {
Schema::table('calendar_settings', function(Blueprint $table) {
$table->string('slack_emoji_importance_half')->after('slack_emoji_importance_full');
});
}

if (!Schema::hasColumn('calendar_settings', 'slack_emoji_importance_empty')) {
Schema::table('calendar_settings', function(Blueprint $table) {
$table->string('slack_emoji_importance_empty')->after('slack_emoji_importance_half');
});
}

$settings['slack_integration'] = setting('kassie.calendar.slack_integration', true);
if (is_null($settings['slack_integration']))
$settings['slack_integration'] = 0;

$settings['slack_webhook'] = setting('kassie.calendar.slack_webhook', true);

$settings['slack_emoji_importance_full'] = setting('kassie.calendar.slack_emoji_importance_full', true);

$settings['slack_emoji_importance_half'] = setting('kassie.calendar.slack_emoji_importance_half', true);

$settings['slack_emoji_importance_empty'] = setting('kassie.calendar.slack_emoji_importance_empty', true);

DB::table('calendar_settings')->insert($settings);
}
}
Loading

0 comments on commit 737d08d

Please sign in to comment.