Compare commits
8 Commits
1.0.0
...
c400020425
Author | SHA1 | Date | |
---|---|---|---|
c400020425 | |||
c0ddd00cc6 | |||
a76ab77757 | |||
5e4e52e620 | |||
f6ac8eae7c | |||
e42c9f4d8f | |||
db95b12985 | |||
a5d97729dc |
@ -12,7 +12,7 @@ class Jobs
|
||||
{
|
||||
use Json;
|
||||
|
||||
public function schedule(ServerRequestInterface $request, ResponseInterface $response, Service $jobsService): ResponseInterface
|
||||
public function schedule(ServerRequestInterface $request, ResponseInterface $response, Service $service, \ProVM\Common\Service\Messages $messagesService): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = \Safe\json_decode($body->getContents());
|
||||
@ -25,17 +25,20 @@ class Jobs
|
||||
'scheduled' => 0
|
||||
];
|
||||
foreach ($json->messages as $message_id) {
|
||||
if ($jobsService->schedule($message_id)) {
|
||||
if ($service->schedule($message_id)) {
|
||||
$message = $messagesService->getRepository()->fetchById($message_id);
|
||||
$message->doesHaveScheduledDownloads();
|
||||
$messagesService->getRepository()->save($message);
|
||||
$output['scheduled'] ++;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
}
|
||||
public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $jobsService): ResponseInterface
|
||||
public function pending(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface
|
||||
{
|
||||
$pending = array_map(function(Job $job) {
|
||||
return $job->toArray();
|
||||
}, $jobsService->getPending());
|
||||
}, $service->getPending());
|
||||
$output = [
|
||||
'total' => count($pending),
|
||||
'pending' => $pending
|
||||
|
@ -83,16 +83,25 @@ class Mailboxes
|
||||
$body = $request->getBody();
|
||||
$json = \Safe\json_decode($body->getContents());
|
||||
if (!isset($json->mailboxes)) {
|
||||
throw new MissingArgument('mailboxes', 'array', 'mailboxes names');
|
||||
throw new MissingArgument('mailboxes', 'array', 'mailboxes ids');
|
||||
}
|
||||
$output = [
|
||||
'mailboxes' => $json->mailboxes,
|
||||
'total' => count($json->mailboxes),
|
||||
'unregistered' => 0
|
||||
'unregistered' => [
|
||||
'total' => 0,
|
||||
'mailboxes' => []
|
||||
]
|
||||
];
|
||||
foreach ($json->mailboxes as $mailbox_id) {
|
||||
$mailbox = $service->getRepository()->fetchById($mailbox_id);
|
||||
if ($service->unregister($mailbox->getName())) {
|
||||
$output['unregistered']['total'] ++;
|
||||
$output['unregistered']['mailboxes'] []= [
|
||||
'id' => $mailbox->getId(),
|
||||
'name' => $mailbox->getName(),
|
||||
'unregistered' => true
|
||||
];
|
||||
foreach ($json->mailboxes as $mailbox_name) {
|
||||
if ($service->unregister($mailbox_name)) {
|
||||
$output['unregistered'] ++;
|
||||
}
|
||||
}
|
||||
return $this->withJson($response, $output);
|
||||
|
@ -118,6 +118,7 @@ class Mailboxes extends Base
|
||||
try {
|
||||
$mailbox = $this->getRepository()->fetchByName($mailbox_name);
|
||||
} catch (BlankResult $e) {
|
||||
$this->getLogger()->error($e);
|
||||
// It's already unregistered
|
||||
return true;
|
||||
}
|
||||
|
@ -108,7 +108,12 @@ class Message implements Model
|
||||
}
|
||||
public function getState(string $name): \ProVM\Emails\Model\State\Message
|
||||
{
|
||||
try {
|
||||
return $this->getStates()[$name];
|
||||
} catch (\Exception $e) {
|
||||
$this->newState($name);
|
||||
return $this->getStates()[$name];
|
||||
}
|
||||
}
|
||||
public function addState(\ProVM\Emails\Model\State\Message $state): Message
|
||||
{
|
||||
@ -127,6 +132,7 @@ class Message implements Model
|
||||
$this->addState((new \ProVM\Emails\Model\State\Message())
|
||||
->setName($name)
|
||||
->setMessage($this)
|
||||
->setValue(false)
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
@ -143,31 +149,31 @@ class Message implements Model
|
||||
{
|
||||
return $this->getState('downloaded_attachments')->getValue() ?? false;
|
||||
}
|
||||
public function hasScheduledDownloads(): bool
|
||||
{
|
||||
return $this->getState('scheduled_downloads')->getValue() ?? false;
|
||||
}
|
||||
|
||||
public function doesHaveAttachments(): Message
|
||||
{
|
||||
if (!isset($this->getState()['has_attachments'])) {
|
||||
$this->newState('has_attachments');
|
||||
}
|
||||
$this->getState('has_attachments')->setValue(true);
|
||||
return $this;
|
||||
}
|
||||
public function doesHaveValidAttachments(): Message
|
||||
{
|
||||
if (!isset($this->getStates()['valid_attachments'])) {
|
||||
$this->newState('valid_attachments');
|
||||
}
|
||||
$this->getState('valid_attachments')->setValue(true);
|
||||
return $this;
|
||||
}
|
||||
public function doesHaveDownloadedAttachments(): Message
|
||||
{
|
||||
if (!isset($this->getStates()['downloaded_attachments'])) {
|
||||
$this->newState('downloaded_attachments');
|
||||
}
|
||||
$this->getState('downloaded_attachments')->setValue(true);
|
||||
return $this;
|
||||
}
|
||||
public function doesHaveScheduledDownloads(): Message
|
||||
{
|
||||
$this->getState('scheduled_downloads')->setValue(true);
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected array $attachments;
|
||||
public function getAttachments(): array
|
||||
@ -205,7 +211,8 @@ class Message implements Model
|
||||
'states' => [
|
||||
'has_attachments' => $this->hasAttachments(),
|
||||
'valid_attachments' => $this->hasValidAttachments(),
|
||||
'downloaded_attachments' => $this->hasDownloadedAttachments()
|
||||
'downloaded_attachments' => $this->hasDownloadedAttachments(),
|
||||
'scheduled_downloads' => $this->hasScheduledDownloads()
|
||||
],
|
||||
'attachments' => $this->hasValidAttachments() ? array_map(function(Attachment $attachment) {
|
||||
return $attachment->toArray();
|
||||
|
@ -111,7 +111,8 @@ class Message extends Repository
|
||||
$valid_states = [
|
||||
'has_attachments',
|
||||
'valid_attachments',
|
||||
'downloaded_attachments'
|
||||
'downloaded_attachments',
|
||||
'scheduled_downloads'
|
||||
];
|
||||
foreach ($valid_states as $state_name) {
|
||||
try {
|
||||
|
17
ui/common/Controller/Api.php
Normal file
17
ui/common/Controller/Api.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Controller;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use ProVM\Common\Service\Api as Service;
|
||||
|
||||
class Api
|
||||
{
|
||||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, Service $service): ResponseInterface
|
||||
{
|
||||
$body = $request->getBody();
|
||||
$json = \Safe\json_decode($body->getContents(), JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
return $service->sendRequest($json);
|
||||
}
|
||||
}
|
47
ui/common/Service/Api.php
Normal file
47
ui/common/Service/Api.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
namespace ProVM\Common\Service;
|
||||
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\RequestFactoryInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class Api
|
||||
{
|
||||
public function __construct(ClientInterface $client, RequestFactoryInterface $factory)
|
||||
{
|
||||
$this->setClient($client)
|
||||
->setFactory($factory);
|
||||
}
|
||||
|
||||
protected ClientInterface $client;
|
||||
protected RequestFactoryInterface $factory;
|
||||
|
||||
public function getClient(): ClientInterface
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
public function getFactory(): RequestFactoryInterface
|
||||
{
|
||||
return $this->factory;
|
||||
}
|
||||
public function setClient(ClientInterface $client): Api
|
||||
{
|
||||
$this->client = $client;
|
||||
return $this;
|
||||
}
|
||||
public function setFactory(RequestFactoryInterface $factory): Api
|
||||
{
|
||||
$this->factory = $factory;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function sendRequest(array $request_data): ResponseInterface
|
||||
{
|
||||
$request = $this->getFactory()->createRequest(strtoupper($request_data['method']) ?? 'GET', $request_data['uri']);
|
||||
if (strtolower($request_data['method']) !== 'get') {
|
||||
$request->getBody()->write(\Safe\json_encode($request_data['data']));
|
||||
$request->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
return $this->getClient()->sendRequest($request);
|
||||
}
|
||||
}
|
4
ui/resources/routes/98_api.php
Normal file
4
ui/resources/routes/98_api.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
use ProVM\Common\Controller\Api;
|
||||
|
||||
$app->post('/api', Api::class);
|
@ -33,8 +33,8 @@
|
||||
).append(
|
||||
$('<button></button>').addClass('ui mini circular red icon button').append(
|
||||
$('<i></i>').addClass('remove icon')
|
||||
).click(() => {
|
||||
this.unregister()
|
||||
).click(e => {
|
||||
this.unregister($(e.currentTarget))
|
||||
})
|
||||
)
|
||||
} else {
|
||||
@ -42,7 +42,7 @@
|
||||
register.append(
|
||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('save icon')
|
||||
).click((e) => {
|
||||
).click(e => {
|
||||
this.register($(e.currentTarget))
|
||||
})
|
||||
)
|
||||
@ -72,20 +72,25 @@
|
||||
})
|
||||
})
|
||||
}
|
||||
unregister() {
|
||||
unregister(button) {
|
||||
const uri = '/mailboxes/unregister'
|
||||
const data = {
|
||||
mailboxes: [this.id]
|
||||
}
|
||||
button.html('').append(
|
||||
$('<i></i>').addClass('redo loading icon')
|
||||
)
|
||||
return Send.delete({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
response.mailboxes.forEach(mb => {
|
||||
if (mb.id === this.id && mb.removed) {
|
||||
response.unregistered.mailboxes.forEach(mb => {
|
||||
if (mb.id === this.id && mb.unregistered) {
|
||||
this.id = null
|
||||
this.registered = false
|
||||
mailboxes.draw().table()
|
||||
const tr = button.parent().parent()
|
||||
tr.html('')
|
||||
this.draw(tr)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -17,7 +17,8 @@
|
||||
states = {
|
||||
attachments: false,
|
||||
valid: false,
|
||||
downloaded: false
|
||||
downloaded: false,
|
||||
scheduled: false
|
||||
}
|
||||
attachments
|
||||
|
||||
@ -81,10 +82,15 @@
|
||||
const map_keys = {
|
||||
has_attachments: 'attachments',
|
||||
valid_attachments: 'valid',
|
||||
downloaded_attachments: 'downloaded'
|
||||
downloaded_attachments: 'downloaded',
|
||||
scheduled_downloads: 'scheduled'
|
||||
}
|
||||
Object.keys(states).forEach(k => {
|
||||
if (k in map_keys) {
|
||||
this.states[map_keys[k]] = states[k]
|
||||
} else {
|
||||
this.states[map_keys[k]] = false
|
||||
}
|
||||
})
|
||||
return this
|
||||
},
|
||||
@ -103,6 +109,9 @@
|
||||
},
|
||||
downloaded: () => {
|
||||
return this.states.downloaded
|
||||
},
|
||||
scheduled: () => {
|
||||
return this.states.scheduled
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,11 +128,17 @@
|
||||
downloaded: () => {
|
||||
this.states.downloaded = true
|
||||
return this
|
||||
},
|
||||
scheduled: () => {
|
||||
this.states.scheduled = true
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draw() {
|
||||
return {
|
||||
row: () => {
|
||||
const format = Intl.DateTimeFormat('es-CL', {dateStyle: 'full', timeStyle: 'short'})
|
||||
let date = new Date()
|
||||
try {
|
||||
@ -141,7 +156,7 @@
|
||||
$('<div></div>').addClass('ui popup').append(list)
|
||||
)
|
||||
}
|
||||
const tr = $('<tr></tr>').append(
|
||||
const tr = $('<tr></tr>').attr('data-id', this.get().id()).append(
|
||||
$('<td></td>').html(this.get().subject())
|
||||
).append(
|
||||
$('<td></td>').html(format.format(date))
|
||||
@ -156,11 +171,7 @@
|
||||
).append(
|
||||
$('<td></td>').append(
|
||||
(this.has().attachments() && this.has().valid() && !this.has().downloaded()) ?
|
||||
$('<button></button>').addClass('ui mini green circular icon button').append(
|
||||
$('<i></i>').addClass('clock icon')
|
||||
).click(() => {
|
||||
this.download().attachments(this.get().id())
|
||||
}) : ''
|
||||
((this.has().scheduled()) ? this.draw().scheduledButton() : this.draw().scheduleButton()) : ''
|
||||
)
|
||||
)
|
||||
if (this.has().downloaded()) {
|
||||
@ -176,23 +187,40 @@
|
||||
})
|
||||
}
|
||||
return tr
|
||||
},
|
||||
scheduleButton: () => {
|
||||
return $('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('clock icon')
|
||||
).click(e => {
|
||||
this.download().attachments(e)
|
||||
})
|
||||
},
|
||||
scheduledButton: () => {
|
||||
return $('<i></i>').addClass('ui green circular inverted check icon')
|
||||
},
|
||||
schedulingButton: () => {
|
||||
return $('<i></i>').addClass('ui circular inverted redo loading icon')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
download() {
|
||||
return {
|
||||
attachments: id => {
|
||||
attachments: event => {
|
||||
const td = $(event.currentTarget).parent()
|
||||
const id = this.get().id()
|
||||
const uri = '/messages/schedule'
|
||||
const data = {
|
||||
messages: [
|
||||
id
|
||||
]
|
||||
}
|
||||
td.html('').append(this.draw().schedulingButton())
|
||||
return Send.put({
|
||||
uri,
|
||||
data
|
||||
}).then(response => {
|
||||
if (response.scheduled > 0) {
|
||||
alert('Scheduled Attachments Job')
|
||||
td.html('').append(this.draw().scheduledButton())
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -205,9 +233,6 @@
|
||||
name: '',
|
||||
count: ''
|
||||
},
|
||||
page: 1,
|
||||
current: 0,
|
||||
shown: 10,
|
||||
total: null,
|
||||
visible: [],
|
||||
get: function() {
|
||||
@ -221,7 +246,13 @@
|
||||
},
|
||||
messages: () => {
|
||||
const uri = '/mailbox/{{$mailbox_id}}/messages/valid'
|
||||
return Send.get(uri).then(response => {
|
||||
return Send.get(uri).then((response, status, jqXHR) => {
|
||||
if (parseInt(jqXHR.status/100) !== 2 || jqXHR.status === 204) {
|
||||
$(this.id.results).html('').append(
|
||||
this.draw().empty()
|
||||
)
|
||||
return
|
||||
}
|
||||
if (this.total === null) {
|
||||
$(this.id.count).html(' (' + response.total + ')')
|
||||
this.total = response.total
|
||||
@ -244,7 +275,6 @@
|
||||
}
|
||||
},
|
||||
draw: function() {
|
||||
const columns = 8
|
||||
return {
|
||||
loader: () => {
|
||||
$(this.id.results).html('').append(
|
||||
@ -264,8 +294,6 @@
|
||||
this.draw().head()
|
||||
).append(
|
||||
this.draw().body()
|
||||
).append(
|
||||
this.draw().footer()
|
||||
)
|
||||
},
|
||||
head: () => {
|
||||
@ -280,43 +308,8 @@
|
||||
}
|
||||
values.push(v)
|
||||
}
|
||||
const dropdown = $('<div></div>').addClass('ui scrolling dropdown').append(
|
||||
$('<i></i>').addClass('dropdown icon')
|
||||
).append(
|
||||
$('<div></div>').addClass('text').html(this.shown)
|
||||
).dropdown({
|
||||
values,
|
||||
onChange: (value, text, $choice) => {
|
||||
if (value === this.shown) {
|
||||
return
|
||||
}
|
||||
this.shown = parseInt(value)
|
||||
// Trigger pending transition
|
||||
$choice.parent().parent().dropdown('hide')
|
||||
this.get()
|
||||
}
|
||||
})
|
||||
|
||||
return $('<thead></thead>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').addClass('right aligned').attr('colspan', columns).append(
|
||||
dropdown
|
||||
).append(
|
||||
$('<span></span>').addClass('ui basic label').html((this.current + 1) + ' - ' + Math.min(this.shown + this.current, this.total ?? 99999999))
|
||||
).append(
|
||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('left chevron icon')
|
||||
).click(() => {
|
||||
this.prev()
|
||||
})
|
||||
).append(
|
||||
$('<button></button>').addClass('ui mini circular icon button').append(
|
||||
$('<i></i>').addClass('right chevron icon')
|
||||
).click(() => {
|
||||
this.next()
|
||||
})
|
||||
)
|
||||
)
|
||||
).append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').html('#')
|
||||
).append(
|
||||
@ -339,7 +332,7 @@
|
||||
body: () => {
|
||||
const tbody = $('<tbody></tbody>')
|
||||
this.visible.forEach((m, i) => {
|
||||
const row = m.draw()
|
||||
const row = m.draw().row()
|
||||
row.prepend(
|
||||
$('<td></td>').html(i + this.current + 1)
|
||||
)
|
||||
@ -347,94 +340,12 @@
|
||||
})
|
||||
return tbody
|
||||
},
|
||||
footer: () => {
|
||||
const pages = this.lastPage()
|
||||
const paging = $('<div></div>').addClass('ui right floated pagination menu')
|
||||
if (this.page !== 1) {
|
||||
paging.append(
|
||||
$('<a></a>').addClass('icon item').append(
|
||||
$('<i></i>').addClass('step backward icon')
|
||||
).click(() => {
|
||||
this.first()
|
||||
})
|
||||
)
|
||||
}
|
||||
for (let i = 0; i < pages; i ++) {
|
||||
const page = $('<a></a>').addClass('item').html(i + 1).click(() => {
|
||||
this.goto(i + 1)
|
||||
})
|
||||
if (i + 1 === this.page) {
|
||||
page.addClass('active')
|
||||
}
|
||||
paging.append(page)
|
||||
}
|
||||
if (this.page !== this.lastPage()) {
|
||||
paging.append(
|
||||
$('<a></a>').addClass('icon item').append(
|
||||
$('<i></i>').addClass('step forward icon')
|
||||
).click(() => {
|
||||
this.last()
|
||||
})
|
||||
)
|
||||
}
|
||||
return $('<tfoot></tfoot>').append(
|
||||
$('<tr></tr>').append(
|
||||
$('<th></th>').attr('colspan', columns).append(paging)
|
||||
)
|
||||
)
|
||||
},
|
||||
empty: () => {
|
||||
$(this.id.count).html(' (0)')
|
||||
return $('<div></div>').addClass('ui message').html('No messages found.')
|
||||
}
|
||||
}
|
||||
},
|
||||
lastPage: function() {
|
||||
let pages = Math.floor(this.total / this.shown)
|
||||
if (this.total / this.shown > pages) {
|
||||
pages ++
|
||||
}
|
||||
return pages
|
||||
},
|
||||
first: function() {
|
||||
if (this.current === 0) {
|
||||
return
|
||||
}
|
||||
this.page = 1
|
||||
this.current = 0
|
||||
this.get()
|
||||
},
|
||||
next: function() {
|
||||
if (this.current + this.shown >= this.total) {
|
||||
return
|
||||
}
|
||||
this.page ++
|
||||
this.current += this.shown
|
||||
this.get()
|
||||
},
|
||||
goto: function(page) {
|
||||
if (this.page === page) {
|
||||
return
|
||||
}
|
||||
this.page = page
|
||||
this.current = (this.page - 1) * this.shown
|
||||
this.get()
|
||||
},
|
||||
prev: function() {
|
||||
if (this.current < this.shown) {
|
||||
return
|
||||
}
|
||||
this.page --
|
||||
this.current -= this.shown
|
||||
this.get()
|
||||
},
|
||||
last: function() {
|
||||
if (this.page === this.lastPage()) {
|
||||
return
|
||||
}
|
||||
this.page = this.lastPage()
|
||||
this.current = (this.page - 1) * this.shown
|
||||
this.get()
|
||||
},
|
||||
setup: function() {
|
||||
this.get().mailbox().then(() => {
|
||||
this.get().messages()
|
||||
|
@ -14,7 +14,8 @@
|
||||
const uri = '/mailboxes/registered'
|
||||
this.draw().loading()
|
||||
return Send.get(uri).then((response, status, jqXHR) => {
|
||||
if (parseInt(jqXHR.status / 100) !== 2) {
|
||||
if (parseInt(jqXHR.status / 100) !== 2 || jqXHR.status === 204) {
|
||||
this.draw().empty()
|
||||
return
|
||||
}
|
||||
if (jqXHR.status === 200) {
|
||||
@ -44,7 +45,7 @@
|
||||
const parent = $(this.div_id)
|
||||
parent.html('')
|
||||
if (this.mailboxes.length === 0) {
|
||||
parent.html('No mailboxes registered.')
|
||||
this.draw().empty()
|
||||
return
|
||||
}
|
||||
const list = $('<div></div>').addClass('ui list')
|
||||
@ -54,6 +55,13 @@
|
||||
)
|
||||
})
|
||||
parent.append(list)
|
||||
},
|
||||
empty: () => {
|
||||
const parent = $(this.div_id)
|
||||
parent.html('')
|
||||
parent.append(
|
||||
$('<div></div>').addClass('ui message').html('No mailboxes registered.')
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,38 +1,33 @@
|
||||
<script type="text/javascript">
|
||||
const Send = {
|
||||
base_url: '{{$urls->api}}',
|
||||
base: function({method, uri, data = null, dataType = 'json', contentType = 'application/json'}) {
|
||||
const url = this.base_url + '/' + uri.replace(/^\//g, '')
|
||||
base: function({method, uri, data = null}) {
|
||||
const request = {
|
||||
uri: uri.replace(/^\//g, ''),
|
||||
method
|
||||
}
|
||||
const options = {
|
||||
method,
|
||||
url,
|
||||
crossDomain: true,
|
||||
headers: {
|
||||
'Authorization': [
|
||||
'Bearer {{$api_key}}'
|
||||
]
|
||||
},
|
||||
dataType
|
||||
url: this.base_url,
|
||||
method: 'post',
|
||||
contentType: 'application/json'
|
||||
}
|
||||
if (method.toLowerCase() !== 'get' && data !== null) {
|
||||
if (!(typeof data === 'string' || data instanceof String)) {
|
||||
options['data'] = JSON.stringify(data)
|
||||
}
|
||||
options['contentType'] = contentType
|
||||
request['data'] = data
|
||||
}
|
||||
options['data'] = JSON.stringify(request)
|
||||
return $.ajax(options)
|
||||
},
|
||||
get: function(uri, dataType = 'json') {
|
||||
return this.base({method: 'get', uri, dataType})
|
||||
get: function(uri) {
|
||||
return this.base({method: 'get', uri})
|
||||
},
|
||||
post: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'post', uri, data, dataType, contentType})
|
||||
post: function({uri, data}) {
|
||||
return this.base({method: 'post', uri, data})
|
||||
},
|
||||
put: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'put', uri, data, dataType, contentType})
|
||||
put: function({uri, data}) {
|
||||
return this.base({method: 'put', uri, data})
|
||||
},
|
||||
delete: function({uri, data, dataType = 'json', contentType = 'application/json'}) {
|
||||
return this.base({method: 'delete', uri, data, dataType, contentType})
|
||||
delete: function({uri, data}) {
|
||||
return this.base({method: 'delete', uri, data})
|
||||
}
|
||||
}
|
||||
const _urls = JSON.parse('{!! Safe\json_encode($urls) !!}')
|
||||
|
@ -2,7 +2,12 @@
|
||||
return [
|
||||
'urls' => function() {
|
||||
$arr = ['base' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']];
|
||||
$arr['api'] = 'http://localhost:8080';
|
||||
$arr['api'] = $_ENV['API_URI'];
|
||||
return (object) $arr;
|
||||
}
|
||||
},
|
||||
'view_urls' => function() {
|
||||
$arr = ['base' => $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST']];
|
||||
$arr['api'] = implode('/', [$arr['base'], 'api']);
|
||||
return (object) $arr;
|
||||
},
|
||||
];
|
||||
|
@ -11,5 +11,8 @@ return [
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
},
|
||||
Psr\Http\Message\RequestFactoryInterface::class => function(ContainerInterface $container) {
|
||||
return $container->get(Nyholm\Psr7\Factory\Psr17Factory::class);
|
||||
},
|
||||
];
|
@ -2,13 +2,13 @@
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
return [
|
||||
\Slim\Views\Blade::class => function(ContainerInterface $container) {
|
||||
return new \Slim\Views\Blade(
|
||||
Slim\Views\Blade::class => function(ContainerInterface $container) {
|
||||
return new Slim\Views\Blade(
|
||||
$container->get('folders')->views,
|
||||
$container->get('folders')->cache,
|
||||
null,
|
||||
[
|
||||
'urls' => $container->get('urls'),
|
||||
'urls' => $container->get('view_urls'),
|
||||
'api_key' => $container->get('api_key')
|
||||
]
|
||||
);
|
||||
|
Reference in New Issue
Block a user