Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add affiliations update button #582

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

veteranmina
Copy link
Contributor

Change would add button in summary card to look like this. If you believe a better location would be rather elsewhere let me know 馃槃
image

@warlof
Copy link
Member

warlof commented Aug 28, 2021

What about putting next to the user button? So we're keeping controls all together.

Move affiliation button to right of user button (Button is slightly larger than user button, UI aesthetically better to have on right.)
@veteranmina
Copy link
Contributor Author

This is how it would look moving it down to the footer.
image

@veteranmina
Copy link
Contributor Author

Further work is needed on this. Do not push this to master.

@warlof
Copy link
Member

warlof commented Aug 30, 2021

As previsouly explained, button is containg "setup" - so when you hit it, it will know what to do and which date to send based on a context. This context is provided by the data attributes.

<button type="button" class="btn btn-sm btn-light" data-widget="esi-update" data-type="{{ $type }}" data-entity="{{ $entity }}" data-job="{{ $job }}" data-url="{{ route('tools.jobs.dispatch') }}">

When you click on it, the following ajax payload is sent against SeAT

{
    "type": "character",
   "entity_id": 0,
   "job_name" : "Job\\FQCN"
}

$('button[data-widget="esi-update"]').on('click', function() {
var button = $(this);
button.find('i').addClass('fa-spin');
$.ajax({
url: button.data('url'),
method: 'POST',
data: {
type: button.data('type'),
entity_id: button.data('entity'),
job_name: button.data('job')
},
success: function() {
button.find('i').removeClass('fa-spin');
},
error: function(e) {
button.addClass('btn-danger');
button.removeClass('btn-light');
console.error(e);
}
});
});
});

Which is processed by this backend

public function postDispatchJob(Request $request)
{
$request->validate([
'type' => 'in:character,corporation,alliance|required',
'entity_id' => 'integer|required',
'job_name' => sprintf('in:%s.%s|required',
$request->input('type'),
implode(',' . $request->input('type') . '.', array_keys(config('web.jobnames.' . $request->input('type'), [])))
),
]);
$job_classes = collect(config(sprintf('web.jobnames.%s', $request->input('job_name'))));
// If we could not find the job to dispatch, log this as a
// security event as someone might be trying something funny.
if ($job_classes->isEmpty()) {
$message = 'Failed to find the class for job_name ' . $request->input('job_name') .
' Someone might be trying something strange.';
event('security.log', [$message, 'jobdispatching']);
return response()->json([
'message' => trans('web::seat.update_failed'),
], 400);
}
// Dispatch jobs for each class
return $this->handleJobDispatch($job_classes, $request);
}

You will need to put a btn-xs class to the button if you want to put it in the card footer, otherwise you'll explode the box.

Also, it might need a bit refactor to be able to use affiliation job since as you noticed, all currently used jobs only took a character ID together with a token as parameter - however, the affiliation job is a bucket and will need an array of stuff.

@warlof
Copy link
Member

warlof commented Jan 25, 2022

Hey @veteranmina , what's the state of this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants