Skip to content

Commit

Permalink
Merge pull request #9 from monsieurbiz/feature/improvements
Browse files Browse the repository at this point in the history
Corrections and list view possibility
  • Loading branch information
maximehuran authored Aug 12, 2021
2 parents d9c4c74 + 9dab61d commit c54e5f7
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 73 deletions.
18 changes: 18 additions & 0 deletions assets/css/app.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Main
// --------------------------------------------------------------------------

@charset "UTF-8";

.fc-list-event-graphic, .fc-list-event-title {
display: none !important;
}

.fc-list-event-time {
cursor: pointer !important;
}

.fc .fc-list-event:hover td {
background: none !important;
font-weight: bold;
}
65 changes: 44 additions & 21 deletions assets/js/app.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Calendar } from "@fullcalendar/core";
import timeGridPlugin from "@fullcalendar/timegrid";
import { Calendar } from '@fullcalendar/core';
import timeGridPlugin from '@fullcalendar/timegrid';
import listPlugin from '@fullcalendar/list';
import allLocales from "@fullcalendar/core/locales-all";
import momentTimezonePlugin from '@fullcalendar/moment-timezone';

import "@fullcalendar/timegrid/main.css";

global.MonsieurBizShippingSlotManager = class {
constructor(
shippingMethodInputs,
nextStepButtons,
calendarContainers,
fullCalendarConfig,
slotStyle,
selectedSlotStyle,
gridSlotStyle,
selectedGridSlotStyle,
listSlotStyle,
selectedListSlotStyle,
initUrl,
listSlotsUrl,
saveSlotUrl,
Expand All @@ -23,8 +24,10 @@ global.MonsieurBizShippingSlotManager = class {
this.nextStepButtons = nextStepButtons;
this.calendarContainers = calendarContainers;
this.fullCalendarConfig = fullCalendarConfig;
this.slotStyle = slotStyle;
this.selectedSlotStyle = selectedSlotStyle;
this.gridSlotStyle = gridSlotStyle;
this.selectedGridSlotStyle = selectedGridSlotStyle;
this.listSlotStyle = listSlotStyle;
this.selectedListSlotStyle = selectedListSlotStyle;
this.initUrl = initUrl;
this.listSlotsUrl = listSlotsUrl;
this.saveSlotUrl = saveSlotUrl;
Expand Down Expand Up @@ -144,7 +147,7 @@ global.MonsieurBizShippingSlotManager = class {
req.open("post", this.saveSlotUrl, true);
req.setRequestHeader("X-Requested-With", "XMLHttpRequest");
let data = new FormData();
data.append("slot", JSON.stringify(slot));
data.append("event", JSON.stringify(slot.event));
data.append("shippingMethod", shippingMethodInput.value);
data.append("shipmentIndex", shippingMethodInput.getAttribute("tabIndex"));
req.send(data);
Expand Down Expand Up @@ -179,17 +182,35 @@ global.MonsieurBizShippingSlotManager = class {
}

applySlotStyle(slot) {
slot.el.querySelector(".fc-event-main").style.color =
this.slotStyle.textColor;
slot.el.style.borderColor = this.slotStyle.borderColor;
slot.el.style.backgroundColor = this.slotStyle.backgroundColor;
if (slot.el.querySelector(".fc-event-main") !== null) {
// Timegrid view
slot.el.querySelector(".fc-event-main").style.color =
this.gridSlotStyle.textColor;
slot.el.style.borderColor = this.gridSlotStyle.borderColor;
slot.el.style.backgroundColor = this.gridSlotStyle.backgroundColor;
} else if (slot.el.querySelector(".fc-list-event-time") !== null) {
// List view
slot.el.querySelector(".fc-list-event-time").style.color =
this.listSlotStyle.textColor;
slot.el.style.borderColor = this.listSlotStyle.borderColor;
slot.el.style.backgroundColor = this.listSlotStyle.backgroundColor;
}
}

applySelectedSlotStyle(slot) {
slot.el.querySelector(".fc-event-main").style.color =
this.selectedSlotStyle.textColor;
slot.el.style.borderColor = this.selectedSlotStyle.borderColor;
slot.el.style.backgroundColor = this.selectedSlotStyle.backgroundColor;
if (slot.el.querySelector(".fc-event-main") !== null) {
// Timegrid view
slot.el.querySelector(".fc-event-main").style.color =
this.selectedGridSlotStyle.textColor;
slot.el.style.borderColor = this.selectedGridSlotStyle.borderColor;
slot.el.style.backgroundColor = this.selectedGridSlotStyle.backgroundColor;
} else if (slot.el.querySelector(".fc-list-event-time") !== null) {
// List view
slot.el.querySelector(".fc-list-event-time").style.color =
this.selectedListSlotStyle.textColor;
slot.el.style.borderColor = this.selectedListSlotStyle.borderColor;
slot.el.style.backgroundColor = this.selectedListSlotStyle.backgroundColor;
}
}

hideSlot(slot) {
Expand All @@ -204,7 +225,7 @@ global.MonsieurBizShippingSlotManager = class {
Object.assign(
{
timeZone: timezone,
plugins: [timeGridPlugin, momentTimezonePlugin],
plugins: [timeGridPlugin, listPlugin, momentTimezonePlugin],
locales: allLocales,
initialView: "timeGridWeek",
contentHeight: "auto",
Expand All @@ -215,9 +236,9 @@ global.MonsieurBizShippingSlotManager = class {
right: "timeGridWeek,timeGridDay",
},
events: events,
eventTextColor: this.slotStyle.textColor,
eventBackgroundColor: this.slotStyle.backgroundColor,
eventBorderColor: this.slotStyle.borderColor,
eventTextColor: this.gridSlotStyle.textColor,
eventBackgroundColor: this.gridSlotStyle.backgroundColor,
eventBorderColor: this.gridSlotStyle.borderColor,
eventClick: function (info) {
// Apply slot selected display
shippingSlotManager.applySelectedSlotStyle(info);
Expand Down Expand Up @@ -247,6 +268,8 @@ global.MonsieurBizShippingSlotManager = class {
shippingSlotManager.applySelectedSlotStyle(info);
shippingSlotManager.previousSlot = info;
shippingSlotManager.enableButtons();
} else {
shippingSlotManager.applySlotStyle(info);
}
},
datesSet(dateInfo) {
Expand Down
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
"devDependencies": {
"@symfony/webpack-encore": "^0.28.1",
"moment-locales-webpack-plugin": "^1.2.0",
"moment-timezone-data-webpack-plugin": "^1.3.0"
"moment-timezone-data-webpack-plugin": "^1.3.0",
"autoprefixer": "^9.7.3",
"node-sass": "^4.13.0",
"postcss-loader": "^3.0.0",
"sass-loader": "^7.3.1"
},
"dependencies": {
"@fullcalendar/core": "^5.7.0",
"@fullcalendar/list": "^5.7.0",
"@fullcalendar/core": "^5.9.0",
"@fullcalendar/list": "^5.9.0",
"@fullcalendar/moment-timezone": "^5.9.0",
"@fullcalendar/rrule": "^5.7.0",
"@fullcalendar/timegrid": "^5.7.0",
"@fullcalendar/rrule": "^5.9.0",
"@fullcalendar/timegrid": "^5.9.0",
"moment": "^2.29.1",
"moment-timezone": "^0.5.31"
}
Expand Down
7 changes: 7 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
plugins: {
autoprefixer: {
cascade: false
}
}
}
6 changes: 3 additions & 3 deletions src/Controller/SlotController.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function saveAction(Request $request): Response
throw $this->createNotFoundException('Shipment index not defined');
}

$slotElement = json_decode($request->get('slot', '{}'), true);
if (!($startDate = $slotElement['event']['start'] ?? false)) {
$event = json_decode($request->get('event', '{}'), true);
if (!($startDate = $event['start'] ?? false)) {
throw $this->createNotFoundException('Start date not defined');
}

Expand All @@ -103,7 +103,7 @@ public function saveAction(Request $request): Response
throw $this->createNotFoundException($e->getMessage());
}

return new JsonResponse($slotElement);
return new JsonResponse($event);
}

public function resetAction(Request $request): Response
Expand Down
4 changes: 1 addition & 3 deletions src/Form/Type/ShippingSlotConfigChoiceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => function(): array {
return $this->shippingSlotConfigRepository->findAll();
},
'choices' => $this->shippingSlotConfigRepository->findAll(),
'choice_value' => 'id',
'choice_label' => 'name',
'empty_data' => '',
Expand Down
1 change: 1 addition & 0 deletions src/Resources/public/css/shipping-slot-css.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Resources/public/css/shipping-slot-js.css

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/Resources/public/entrypoints.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
"entrypoints": {
"shipping-slot-js": {
"css": [
"/public/shipping-slot-js.css"
"/public/css/shipping-slot-js.css"
],
"js": [
"/public/js/shipping-slot-js.js"
]
},
"shipping-slot-css": {
"css": [
"/public/css/shipping-slot-css.css"
]
}
}
}
55 changes: 23 additions & 32 deletions src/Resources/public/js/shipping-slot-js.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Resources/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"public/shipping-slot-js.css": "/public/shipping-slot-js.css",
"public/shipping-slot-css.css": "/public/css/shipping-slot-css.css",
"public/shipping-slot-js.css": "/public/css/shipping-slot-js.css",
"public/shipping-slot-js.js": "/public/js/shipping-slot-js.js"
}
1 change: 0 additions & 1 deletion src/Resources/public/shipping-slot-js.css

This file was deleted.

3 changes: 2 additions & 1 deletion src/Resources/views/Shop/_styles.html.twig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/monsieurbizsyliusshippingslotplugin/shipping-slot-js.css'} %}
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/monsieurbizsyliusshippingslotplugin/css/shipping-slot-js.css'} %}
{% include '@SyliusUi/_stylesheets.html.twig' with {'path': 'bundles/monsieurbizsyliusshippingslotplugin/css/shipping-slot-css.css'} %}
20 changes: 16 additions & 4 deletions src/Resources/views/Shop/app.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@
let shippingMethodInputs = document.querySelectorAll('input[type="radio"][name*="sylius_checkout_select_shipping"]');
let nextStepButtons = document.querySelectorAll('form[name="sylius_checkout_select_shipping"] button#next-step');
let calendarContainers = document.querySelectorAll('.monsieurbiz_shipping_slot_calendar');
let slotStyle = {
let gridSlotStyle = {
textColor: '#ffffff',
borderColor: '#3788d8',
backgroundColor: '#3788d8',
};
let selectedSlotStyle = {
let selectedGridSlotStyle = {
textColor: '#3788d8',
borderColor: '#3788d8',
backgroundColor: '#ffffff',
};
let listSlotStyle = {
textColor: '#ffffff',
borderColor: '#3788d8',
backgroundColor: '#3788d8',
};
let selectedListSlotStyle = {
textColor: '#3788d8',
borderColor: '#3788d8',
backgroundColor: '#ffffff',
Expand All @@ -29,8 +39,10 @@
nextStepButtons,
calendarContainers,
fullCalendarConfig,
slotStyle,
selectedSlotStyle,
gridSlotStyle,
selectedGridSlotStyle,
listSlotStyle,
selectedListSlotStyle,
'{{ url("monsieurbiz_shippingslot_checkout_init", {"code": "__CODE__"})|e('js') }}',
'{{ url("monsieurbiz_shippingslot_checkout_listslots", {"code": "__CODE__", "fromDate": "__FROM__", "toDate": "__TO__"})|e('js') }}',
'{{ url("monsieurbiz_shippingslot_checkout_saveslot")|e('js') }}',
Expand Down
9 changes: 8 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ Encore

// entries
.addEntry('shipping-slot-js', './assets/js/app.js')
.addStyleEntry('shipping-slot-css', './assets/css/app.scss')

// configuration
.disableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())

// enables Sass/SCSS support
.enableSassLoader()
// enables PostCSS support
.enablePostCssLoader()

// organise files
.configureFilenames({
js: 'js/[name].js'
js: 'js/[name].js',
css: 'css/[name].css',
})
;

Expand Down

0 comments on commit c54e5f7

Please sign in to comment.