wip send client when creating calendar object

This commit is contained in:
Tiavina 2024-12-19 16:18:58 +03:00
parent a9e5a3441b
commit 72bb3360f9
15 changed files with 226 additions and 2 deletions

View File

@ -28,11 +28,13 @@ use OCA\Calendar\Dashboard\CalendarWidget;
use OCA\Calendar\Dashboard\CalendarWidgetV2; use OCA\Calendar\Dashboard\CalendarWidgetV2;
use OCA\Calendar\Events\BeforeAppointmentBookedEvent; use OCA\Calendar\Events\BeforeAppointmentBookedEvent;
use OCA\Calendar\Listener\AppointmentBookedListener; use OCA\Calendar\Listener\AppointmentBookedListener;
use OCA\Calendar\Listener\CalendarObjectCreatedListener;
use OCA\Calendar\Listener\CalendarReferenceListener; use OCA\Calendar\Listener\CalendarReferenceListener;
use OCA\Calendar\Listener\UserDeletedListener; use OCA\Calendar\Listener\UserDeletedListener;
use OCA\Calendar\Notification\Notifier; use OCA\Calendar\Notification\Notifier;
use OCA\Calendar\Profile\AppointmentsAction; use OCA\Calendar\Profile\AppointmentsAction;
use OCA\Calendar\Reference\ReferenceProvider; use OCA\Calendar\Reference\ReferenceProvider;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
@ -73,7 +75,7 @@ class Application extends App implements IBootstrap {
$context->registerEventListener(BeforeAppointmentBookedEvent::class, AppointmentBookedListener::class); $context->registerEventListener(BeforeAppointmentBookedEvent::class, AppointmentBookedListener::class);
$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
$context->registerEventListener(RenderReferenceEvent::class, CalendarReferenceListener::class); $context->registerEventListener(RenderReferenceEvent::class, CalendarReferenceListener::class);
$context->registerEventListener(CalendarObjectCreatedEvent::class, CalendarObjectCreatedListener::class);
$context->registerNotifierService(Notifier::class); $context->registerNotifierService(Notifier::class);
} }

View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/*
* @copyright 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @author 2022 Christoph Wurst <christoph@winzerhof-wurst.at>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OCA\Calendar\Listener;
use OCA\Calendar\Service\Appointments\BookingService;
use OCA\Calendar\Service\Calendar\CalendarService;
use OCA\DAV\Events\CalendarObjectCreatedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use Psr\Log\LoggerInterface;
class CalendarObjectCreatedListener implements IEventListener {
/** @var LoggerInterface */
private $logger;
/** @var \OCA\Calendar\Service\Calendar\CalendarService* */
private $calendarService;
public function __construct(
LoggerInterface $logger,CalendarService $calendarService) {
$this->logger = $logger;
$this->calendarService = $calendarService;
}
public function handle(Event $event): void {
if (!($event instanceof CalendarObjectCreatedEvent)) {
return;
}
$calendarData = $event->getObjectData();
$vCalendarString = $calendarData["calendardata"];
$calendarSummary = $this->calendarService->GetCalendarSummaryFromVCalendarString($vCalendarString);
$this->calendarService->createDefuntFromCalendarSummary($calendarSummary);
}
}

View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Calendar\Service\Calendar;
use OCA\Gestion\Db\Bdd;
use Psr\Log\LoggerInterface;
class CalendarService {
/** @var Bdd */
private $gestionMapper;
/** @var LoggerInterface */
private $logger;
public function __construct(
Bdd $gestionMapper,
LoggerInterface $logger) {
$this->logger = $logger;
$this->gestionMapper = $gestionMapper;
}
public function createDefuntFromCalendarSummary($calendarSummary): bool{
return $this->gestionMapper->insertDefuntByName($calendarSummary);
}
public function GetCalendarSummaryFromVCalendarString(string $vCalendarString): string
{
$summaryValue = "Nom du défunt";
preg_match('/SUMMARY:(.*)\r\n/', $vCalendarString, $matches);
if (isset($matches[1])) {
$summaryValue = trim($matches[1]);
}
return $summaryValue;
}
}

View File

@ -99,6 +99,17 @@ export default {
location() { location() {
return this.calendarObjectInstance?.location ?? null return this.calendarObjectInstance?.location ?? null
}, },
/**
* Returns the client or null if the event is still loading
*
* @return {string|null}
*/
client() {
return this.calendarObjectInstance?.client ?? null
},
/** /**
* Returns the description or null if the event is still loading * Returns the description or null if the event is still loading
* *
@ -322,7 +333,7 @@ export default {
* Returns an object with properties from RFCs including * Returns an object with properties from RFCs including
* their displayName, a description, options, etc. * their displayName, a description, options, etc.
* *
* @return {{geo, color, timeTransparency, description, resources, location, categories, accessClass, priority, status, locations, articles}} * @return {{geo, color, timeTransparency, description, resources, location, client, categories, accessClass, priority, status, locations, articles, clients}}
*/ */
rfcProps() { rfcProps() {
return getRFCProperties() return getRFCProperties()
@ -476,6 +487,7 @@ export default {
* @return {Promise<void>} * @return {Promise<void>}
*/ */
async save(thisAndAllFuture = false) { async save(thisAndAllFuture = false) {
console.log("MIDITRA ATO NY SAVE",this.calendarObject);
if (!this.calendarObject) { if (!this.calendarObject) {
logger.error('Calendar-object not found') logger.error('Calendar-object not found')
return return
@ -594,6 +606,19 @@ export default {
location, location,
}) })
}, },
/**
* Updates the client of the event
*
* @param {string} client New client
*/
updateClient(client) {
this.$store.commit('changeClient', {
calendarObjectInstance: this.calendarObjectInstance,
client,
})
},
/** /**
* Updates the start date of this event * Updates the start date of this event
* *

View File

@ -106,6 +106,7 @@ const mapCDavObjectToCalendarObject = (dav, calendarId) => {
* @return {object} * @return {object}
*/ */
const mapCalendarJsToCalendarObject = (calendarComponent, calendarId = null) => { const mapCalendarJsToCalendarObject = (calendarComponent, calendarId = null) => {
console.log("Ary ato mapCalendarJsToCalendarObject");
const vObjectIterator = calendarComponent.getVObjectIterator() const vObjectIterator = calendarComponent.getVObjectIterator()
const firstVObject = vObjectIterator.next().value const firstVObject = vObjectIterator.next().value
if (!firstVObject) { if (!firstVObject) {

View File

@ -56,6 +56,8 @@ const getDefaultEventObject = (props = {}) => Object.assign({}, {
canModifyAllDay: true, canModifyAllDay: true,
// Location that the event takes places in // Location that the event takes places in
location: null, location: null,
//client of the event
client : null,
// description of the event // description of the event
description: null, description: null,
// Access class of the event (PUBLIC, PRIVATE, CONFIDENTIAL) // Access class of the event (PUBLIC, PRIVATE, CONFIDENTIAL)
@ -102,6 +104,7 @@ const mapEventComponentToEventObject = (eventComponent) => {
isAllDay: eventComponent.isAllDay(), isAllDay: eventComponent.isAllDay(),
canModifyAllDay: eventComponent.canModifyAllDay(), canModifyAllDay: eventComponent.canModifyAllDay(),
location: eventComponent.location, location: eventComponent.location,
client : eventComponent.client,
description: eventComponent.description, description: eventComponent.description,
accessClass: eventComponent.accessClass, accessClass: eventComponent.accessClass,
status: eventComponent.status, status: eventComponent.status,
@ -199,6 +202,7 @@ const mapEventComponentToEventObject = (eventComponent) => {
const copyCalendarObjectInstanceIntoEventComponent = (eventObject, eventComponent) => { const copyCalendarObjectInstanceIntoEventComponent = (eventObject, eventComponent) => {
eventComponent.title = eventObject.title eventComponent.title = eventObject.title
eventComponent.location = eventObject.location eventComponent.location = eventObject.location
eventComponent.client = eventObject.client
eventComponent.description = eventObject.description eventComponent.description = eventObject.description
eventComponent.accessClass = eventObject.accessClass eventComponent.accessClass = eventObject.accessClass
eventComponent.status = eventObject.status eventComponent.status = eventObject.status

View File

@ -125,6 +125,23 @@ const getRFCProperties = () => {
options: [], options: [],
}, },
clients: {
readableName: t('calendar', 'Clients'),
icon: 'Tag',
searchable: true,
multiple: false,
info: t('calendar', 'Client from Gestion'),
placeholder: t('calendar', 'Add client'),
tagPlaceholder: t('calendar', 'Add client'),
options: [],
},
client: {
readableName: t('calendar', 'client'),
placeholder: t('calendar', 'Add a client'),
icon: 'MapMarker',
},
articles: { articles: {
readableName: t('calendar', 'Articles'), readableName: t('calendar', 'Articles'),
icon: 'TextBoxOutline', icon: 'TextBoxOutline',

View File

@ -321,6 +321,12 @@ const mutations = {
calendarObjectInstance.location = location calendarObjectInstance.location = location
}, },
changeClient(state, { calendarObjectInstance, client }) {
console.log("CHANGE CLIENT STORE", client);
calendarObjectInstance.eventComponent.client = client
calendarObjectInstance.client = client
},
/** /**
* Change the description of an event * Change the description of an event
* *
@ -1656,6 +1662,10 @@ const actions = {
async saveCalendarObjectInstance({ state, dispatch, commit }, { thisAndAllFuture, calendarId }) { async saveCalendarObjectInstance({ state, dispatch, commit }, { thisAndAllFuture, calendarId }) {
const eventComponent = state.calendarObjectInstance.eventComponent const eventComponent = state.calendarObjectInstance.eventComponent
const calendarObject = state.calendarObject const calendarObject = state.calendarObject
debugger
console.log("EVENNNNNNNTTT COMPONENTTTTT", eventComponent);
console.log("CALEEEEENNNDDDARRRR OBJEEEEEEEECCCCC TTTTTTT",calendarObject);
updateAlarms(eventComponent) updateAlarms(eventComponent)
updateTalkParticipants(eventComponent) updateTalkParticipants(eventComponent)
@ -1683,6 +1693,7 @@ const actions = {
} }
if (calendarId !== state.calendarObject.calendarId) { if (calendarId !== state.calendarObject.calendarId) {
console.log("MIDITRA ATO AMIN NY MOVE CALENDAR");
await dispatch('moveCalendarObject', { await dispatch('moveCalendarObject', {
calendarObject, calendarObject,
newCalendarId: calendarId, newCalendarId: calendarId,

View File

@ -505,6 +505,7 @@ const actions = {
'SUMMARY', 'SUMMARY',
'LOCATION', 'LOCATION',
'DESCRIPTION', 'DESCRIPTION',
'CLIENT'
]) ])
}, },
} }

View File

@ -31,6 +31,7 @@
<EmptyCalendar v-else /> <EmptyCalendar v-else />
<EditSimple v-if="showWidgetEventDetails" :is-widget="true" :locations="locations" /> <EditSimple v-if="showWidgetEventDetails" :is-widget="true" :locations="locations" />
<EditSimple v-if="showWidgetEventDetails" :is-widget="true" :clients="clients" />
</div> </div>
<NcContent v-else app-name="calendar calendar-custom" :class="classNames"> <NcContent v-else app-name="calendar calendar-custom" :class="classNames">

View File

@ -103,6 +103,14 @@
@update-end-timezone="updateEndTimezone" @update-end-timezone="updateEndTimezone"
@toggle-all-day="toggleAllDay" /> @toggle-all-day="toggleAllDay" />
<PropertySelectAjax class="property-location"
url="/apps/gestion/ajaxGetClientsName"
:is-read-only="isReadOnly"
:prop-model="rfcProps.clients"
:value="client"
:linkify-links="true"
@update:value="updateClient" />
<PropertySelectAjax class="property-location" <PropertySelectAjax class="property-location"
url="/apps/gestion/ajaxGetLieux" url="/apps/gestion/ajaxGetLieux"
:is-read-only="isReadOnly" :is-read-only="isReadOnly"

View File

@ -121,6 +121,14 @@
@update-end-timezone="updateEndTimezone" @update-end-timezone="updateEndTimezone"
@toggle-all-day="toggleAllDay" /> @toggle-all-day="toggleAllDay" />
<PropertySelectAjax class="property-location"
url="/apps/gestion/ajaxGetClientsName"
:is-read-only="isReadOnly"
:prop-model="rfcProps.clients"
:value="client"
:linkify-links="true"
@update:value="updateClient" />
<PropertySelectAjax class="property-location" <PropertySelectAjax class="property-location"
url="/apps/gestion/ajaxGetLieux" url="/apps/gestion/ajaxGetLieux"
:is-read-only="isReadOnly" :is-read-only="isReadOnly"

View File

@ -49,6 +49,7 @@ return [
['name' => 'page#ajaxGetLieux', 'url' => '/ajaxGetLieux', 'verb' => 'GET'], ['name' => 'page#ajaxGetLieux', 'url' => '/ajaxGetLieux', 'verb' => 'GET'],
['name' => 'page#ajaxGetArticles', 'url' => '/ajaxGetArticles', 'verb' => 'GET'], ['name' => 'page#ajaxGetArticles', 'url' => '/ajaxGetArticles', 'verb' => 'GET'],
['name' => 'page#ajaxGetProduits', 'url' => '/ajaxGetProduits', 'verb' => 'GET'], ['name' => 'page#ajaxGetProduits', 'url' => '/ajaxGetProduits', 'verb' => 'GET'],
['name' => 'page#ajaxGetClientsName', 'url' => '/ajaxGetClientsName', 'verb' => 'GET'],
['name' => 'page#getLieux', 'url' => '/getLieux', 'verb' => 'PROPFIND'], ['name' => 'page#getLieux', 'url' => '/getLieux', 'verb' => 'PROPFIND'],
['name' => 'page#insertLieu', 'url' => '/lieu/insert', 'verb' => 'POST'], ['name' => 'page#insertLieu', 'url' => '/lieu/insert', 'verb' => 'POST'],

View File

@ -1257,6 +1257,14 @@ class PageController extends Controller {
return $this->myDb->getLieux($this->idNextcloud); return $this->myDb->getLieux($this->idNextcloud);
} }
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function ajaxGetClientsName() {
return $this->myDb->getClientsName();
}
/** /**
* @NoAdminRequired * @NoAdminRequired
* @NoCSRFRequired * @NoCSRFRequired

View File

@ -53,6 +53,13 @@ class Bdd {
return $this->execSQL($sql, array()); return $this->execSQL($sql, array());
} }
public function getClientsName(){
$sql = "SELECT client.nom, client.prenom, client.id
FROM ".$this->tableprefix."client as client
ORDER BY client.id DESC";
return $this->execSQL($sql, array());
}
public function getClient($id,$idNextcloud){ public function getClient($id,$idNextcloud){
$sql = "SELECT * FROM ".$this->tableprefix."client WHERE id = ?"; $sql = "SELECT * FROM ".$this->tableprefix."client WHERE id = ?";
return $this->execSQL($sql, array($id)); return $this->execSQL($sql, array($id));
@ -653,6 +660,18 @@ class Bdd {
return true; return true;
} }
/**
* Insert Defunt
*/
public function insertDefuntByName($name) {
$sql = "INSERT INTO `".$this->tableprefix."defunt` (
`id_nextcloud`, `nom`, `sexe`, `date_naissance`, `ref_pacemaker`, `date`,
`corpulence`, `observations_corps`, `observations_generales`
) VALUES (?,?,?,?,?,NOW(),?,?,?);";
$this->execSQLNoData($sql, array('admin',$name, 'm', '1973-11-11', 'Référence pacemaker', '', '', ''));
return true;
}
/** /**
* Insert lieu * Insert lieu
*/ */