Skip to content

Instantly share code, notes, and snippets.

@alnutile
Created May 1, 2015 14:56
Show Gist options
  • Save alnutile/d50ad6339a8ddb1e48b3 to your computer and use it in GitHub Desktop.
Save alnutile/d50ad6339a8ddb1e48b3 to your computer and use it in GitHub Desktop.
Events to listen to and steps
<?php
// Composer: "fzaninotto/faker": "v1.3.0"
use Approve\Comparisons\Comparison;
use Faker\Factory as Faker;
class ComparisonsTableSeeder extends BaseSeeder {
public $states = [
'Error',
'Complete',
'Not Compared Yet',
'In Progress',
'Files Not Fully Uploaded',
'One of Two Files Done',
'In Progress Quick Diff',
'Pending User Starting Comparison'
];
public function run()
{
$this->makeStates();
$this->makeComparisons('mock-project-1', 'mock-request-1', 'mock-comparison-1', false, 'error');
$this->makeComparisons('mock-project-1', 'mock-request-2', 'mock-comparison-2', false, 'not-compared-yet');
$this->makeComparisons('mock-project-1', 'mock-request-3', 'mock-comparison-3', false, 'complete');
$this->makeComparisons('mock-project-1', 'mock-request-4', 'mock-comparison-4', false, 'in-progress');
}
private function makeComparisons($project_id, $rendertree_diff_id, $id = false, $name = false, $state_id = false, $number = 1)
{
foreach(range(1, $number) as $index)
{
Comparison::create(
[
'id' => ($id) ? $id : $this->faker->uuid,
'name' => ($name) ? $name : "Mock Comparison " . rand(1,100),
'comparison_state_id' => ($state_id) ? $state_id : 'not-compared-yet',
'project_id' => "mock-project-" . $index,
'diff_id' => $rendertree_diff_id,
'change_amount' => ($state_id == 'complete') ? rand(0,100) : 0
]
);
}
}
private function makeStates()
{
foreach($this->states as $state)
{
\Approve\Comparisons\ComparisonState::create(
[
'id' => $this->transForm($state),
'name' => $state,
]
);
}
}
protected function transform($state)
{
return strtolower(str_replace(" ", "-", $state));
}
}
<?php
/**
* Created by PhpStorm.
* User: andrewcavanagh
* Date: 3/30/15
* Time: 8:05 PM
*/
namespace Approve\PdfUpload;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
class Listener extends ServiceProvider{
public function register()
{
//
}
/**
* We only care if the Comparison with the job id has a related diff_request
*/
public function boot()
{
$this->app['events']->listen('job.complete.success', function()
{
//Are we ready for first render tree diff?
//
//If stage = 'one-of-two-files-done'
// then we are ready to make the render tree diff request
// send to rt api
// update stage to in-progress-quick-diff
// Notify ui of new status
//
//Else
// set it to 'one-of-two-files-done'
// notify ui of file a or b being done processing
// trigger upload of files to s3 and make compare.json file
});
$this->app['events']->listen('diff.complete.success', function()
{
//Once during first compare
//Once during final deeper compare
//If stage = 'in-progress-quick-diff'
// Then we need to react to that
// Update compare.json to show these new results
// Set State to pending-user-starting-comparison
// notify ui and user via bell and later email
});
/**
* Notify User
* Notify UI
*/
$this->app['events']->listen('diff.ready_to_view_in_drag_and_drop_compare', function() {
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment