9 lines
33 KiB
JavaScript
9 lines
33 KiB
JavaScript
|
'use strict';function _extends(){return _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_extends.apply(this,arguments)}function _typeof(a){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0// hack: remove weird animation after a drop
|
||
|
,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}function _iterableToArrayLimit(a,b){if(Symbol.iterator in Object(a)||"[object Arguments]"===Object.prototype.toString.call(a)){var c=[],d=!0,e=!1,f=void 0;try{for(var g,h=a[Symbol.iterator]();!(d=(g=h.next()).done)&&(c.push(g.value),!(b&&c.length===b));d=!0);}catch(a){e=!0,f=a}finally{try{d||null==h["return"]||h["return"]()}finally{if(e)throw f}}return c}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(b,!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(b).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _defineProperty(a,b,c){return b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}var _window$ReactBeautifu=window.ReactBeautifulDnd,DragDropContext=_window$ReactBeautifu.DragDropContext,Draggable=_window$ReactBeautifu.Draggable,Droppable=_window$ReactBeautifu.Droppable,data=window.shop_data,productStyle=function(a,b,c,d,e){var f={opacity:b.isDragging?.7:1,backgroundColor:d||e?"#eae7f7":"initial"};return b.isDropAnimating?(c&&(f.transitionDuration="0.001s"),_objectSpread({},a,{},f)):_objectSpread({},a,{},f)},cartStyle=function(a,b){var c=b.isDraggingOver;return _objectSpread({},a,{},{backgroundColor:c?"#f2f2f2":"#f9f9f9",border:c?"1px dashed #ccc":"0"})},nbrConnectorsStyle=function(a){if(!a||!a.nbrCurrentSlot)return{};var b=100*a.nbrCurrentSlot/a.nbrSlotMax;return 100<b&&(b=100),{width:"".concat(b,"%")}},nbrClocksStyle=function(a){if(!a||!a.nbrCurrentClock)return{};var b=100*a.nbrCurrentClock/a.nbrClockMax;return 100<b&&(b=100),{width:"".concat(b,"%")}},copy=function(a,b,c,d,e){var f=Array.from(b.itemIds),g=Array.from(c.items),h=f[d.index];return g.splice(e.index,0,_objectSpread({},a[h],{id:uuidv4()})),g},reorder=function(a,b,c){var d=Array.from(a),e=d.splice(b,1),f=_slicedToArray(e,1),g=f[0];return d.splice(c,0,g),d},remove=function(a,b){var c=Array.from(a);return c.splice(b,1),c},nbrOccupiedSlotsInCrate=function(a){return a.reduce(function(a,b){return a+(8===b.hp?2:1)},0)},Layout=/*#__PURE__*/function(a){function b(){return _classCallCheck(this,b),_possibleConstructorReturn(this,_getPrototypeOf(b).apply(this,arguments))}return _inherits(b,a),_createClass(b,[{key:"render",value:function render(){var a=this.props,b=a.aside,c=a.main;return React.createElement("div",{className:"layout"},React.createElement("aside",{className:"aside"},b),React.createElement("section",{className:"main"},c))}}],[{key:"propTypes"
|
||
|
this.handleOnDragEnd({source:{droppableId:"backlog",index:0},destination:{droppableId:"cart",index:0},draggableId:null})}},{key:"componentDidUpdate",value:function componentDidUpdate(a,b){(b.columns.cart.items!==this.state.columns.cart.items||b.currentMode!==this.state.currentMode)&&this.checkAlerts(b.columns.cart.items,this.state.columns.cart.items)}},{key:"handleCrateModeChange",value:function handleCrateModeChange(a){this.setState({currentMode:a})}},{key:"handleDeleteItem",value:function handleDeleteItem(a){var b=Array.from(this.state.columns.cart.items);b.splice(a,1),this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:b})})}))}},{key:"handleDeleteAllItems",value:function handleDeleteAllItems(){this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:[]})})}))}},{key:"handleMouseEnterItem",value:function handleMouseEnterItem(a){this.setState(_objectSpread({},this.state,{currentItemHovered:a}))}},{key:"handleMouseLeaveItem",value:function handleMouseLeaveItem(){this.setState(_objectSpread({},this.state,{currentItemHovered:null}))}},{key:"handleClickAddItem",value:function handleClickAddItem(a){var b={droppableId:"cart",index:this.state.columns.cart.items.length};this.handleOnDragEnd({source:{droppableId:"backlog",index:a},destination:b,draggableId:null})}},{key:"handleToggleItemProgress",value:function handleToggleItemProgress(a,b){var c=Array.from(this.state.columns.cart.items);this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:c.map(function(c,d){return _objectSpread({},c,{showProgress:d===a&&b,showOverlayRemove:!1,showWarning:!1})})})})}))}},{key:"handleToggleItemWarning",value:function handleToggleItemWarning(a,b){var c=Array.from(this.state.columns.cart.items);this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:c.map(function(c,d){return _objectSpread({},c,{showWarning:d===a&&b,showProgress:!1,showOverlayRemove:!1})})})})}))}},{key:"handleClickSelectItem",value:function handleClickSelectItem(a){var b=Array.from(this.state.columns.cart.items);this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:b.map(function(b,c){return _objectSpread({},b,{selected:c===a})})})})}))}},{key:"handleToggleOverlayRemove",value:function handleToggleOverlayRemove(a,b){var c=Array.from(this.state.columns.cart.items);this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{items:c.map(function(c,d){return _objectSpread({},c,{showOverlayRemove:d===a&&b,showProgress:!1,showWarning:!1})})})})}))}},{key:"handleClickSubmit",value:function handleClickSubmit(b){var c={items:[],type:this.state.currentMode},d=Array.from(this.state.columns.cart.items);for(var g in d){var h=d[g];c.items.push({name:h.name})}var e=document.createElement("a"),a=new Date().getTime(),f="Hello!\n\nI would like to request a quotation for my below configuration:\n\n".concat(JSON.stringify(c),"\n\n");b&&(f="".concat(f,"\n\nAdditional note:\n\n").concat(b?b.trim():"")),document.body.appendChild(e),e.style="display: none",e.href="mailto:sales@m-labs.hk?subject=".concat("[Order hardware] - Request Quote","&body=").concat(encodeURIComponent(f)),e.click()}},{key:"handleOnDragEnd",value:function handleOnDragEnd(a){var b=a.source,c=a.destination,d=a.draggableId;if(!c)return void("cart"===b.droppableId&&this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,_defineProperty({},b.droppableId,_objectSpread({},this.state.columns[b.droppableId],{items:remove(this.state.columns[b.droppableId].items,b.index)})))})));switch(b.droppableId){case"backlog":this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,_defineProper
|
||
|
for(var u=h.reduce(function(a,b,c){return("kasli"===b.type||"kasli-backplane"===b.type||"clocker"===b.type)&&a.push(c),a},[]),v=0;v<=u.length-1;v++){var w=void 0,x=0,y=u[v];w=v==u.length-1?h.slice(y+1):h.slice(y+1,u[v+1]),x=w.reduce(function(a,b){return a+b.clockOccupied},0),y in j?j[y].nbrCurrentClock?j[y].nbrCurrentClock+=x:j[y].nbrCurrentClock=x:(j[y]=_objectSpread({},h[y]),j[y].nbrCurrentClock=x,j[y].warnings={}),x>h[y].nbrClockMax&&(k[h[y].rules.maxClock.type]=_objectSpread({},h[y].rules.maxClock),j[y].warnings.maxClockWarning=_objectSpread({},h[y].rules.maxClockWarning))}// check for number of recommanded EEM connectors
|
||
|
["novo","urukul","koster"].map(function(a){return h.find(function(b){return b.type===a})&&(k[c.state.items[a].rules.connectors.type]=_objectSpread({},c.state.items[a].rules.connectors)),a});for(var z=h.reduce(function(a,b,c){return"idc-bnc"===b.type&&a.push(c),a},[]),A=z.length-1;0<=A;A--){var B=z[A],C=!1;if(0==B)C=!0;else if(1<=B){var H=z[A]-1;"zotino"!==h[H].type&&"hd68"!==h[H].type&&"idc-bnc"!==h[H].type&&(C=!0)}C&&(j[B]=_objectSpread({},h[B]),j[B].warnings={},j[B].warnings.wrong=_objectSpread({},h[B].rules.wrong))}// check number of IDC-BNC adapters for a Zotino and HD68-IDC
|
||
|
for(var D=h.reduce(function(a,b,c){return("zotino"===b.type||"hd68"===b.type)&&a.push(c),a},[]),E=function(a){var b=void 0,c=0,d=D[a];b=a===D.length-1?h.slice(d+1):h.slice(d+1,D[a+1]);var e=!1;// check if HD68-IDC has at least 1 IDC-BNC adapter
|
||
|
if(c=b.reduce(function(a,b,c,d){return 0===c&&"idc-bnc"===b.type?a+1:"idc-bnc"===d[0].type&&0<c&&"idc-bnc"===d[c-1].type?("idc-bnc"!==b.type&&(e=!0),a+("idc-bnc"!==b.type||e?0:1)):a},0),(d in j)?(j[d].nbrCurrentSlot=c,!("warnings"in j[d])&&(j[d].warnings={})):(j[d]=_objectSpread({},h[d]),j[d].nbrCurrentSlot=c,j[d].warnings={}),0<c&&(k[h[d].rules.maxSlot.type]=_objectSpread({},h[d].rules.maxSlot)),c>h[d].nbrSlotMax&&(j[d].warnings.maxSlotWarning=_objectSpread({},h[d].rules.maxSlotWarning)),"hd68"===h[d].type){var f=!1;d<h.length-1?"idc-bnc"!==h[d+1].type&&(f=!0):d===h.length-1&&(f=!0),f&&((d in j)?j[d].warnings.minAdapter=_objectSpread({},h[d].rules.minAdapter):(j[d]=_objectSpread({},h[d]),j[d].warnings={},j[d].warnings.minAdapter=_objectSpread({},h[d].rules.minAdapter)))}},F=0;F<=D.length-1;F++)E(F);// update state with rules
|
||
|
this.setState(_objectSpread({},this.state,{columns:_objectSpread({},this.state.columns,{cart:_objectSpread({},this.state.columns.cart,{itemsData:_objectSpread({},j)})}),rules:_objectSpread({},k)}))}},{key:"render",value:function render(){var a=this.state,b=a.currentItemHovered,c=a.currentMode,d=a.crateModeSlots,e=a.crateModeItems,f=a.items,g=a.columns,h=a.rules;return React.createElement(DragDropContext,{onDragEnd:this.handleOnDragEnd},React.createElement(Layout,{className:"shop",aside:React.createElement(Backlog,{items:f,data:g.backlog,onClickAddItem:this.handleClickAddItem}),main:React.createElement(OrderPanel,{title:"Order hardware",description:" Choose your crate and drag/add the cards you want to the crate below to see how the combination would look like.",crateMode:React.createElement(CrateMode,{items:e,mode:c,onClickMode:this.handleCrateModeChange}),crate:React.createElement(Crate,{cart:React.createElement(Cart,{nbrSlots:d[c],data:g.cart,itemHovered:b,onToggleProgress:this.handleToggleItemProgress,onToggleWarning:this.handleToggleItemWarning,onToggleOverlayRemove:this.handleToggleOverlayRemove,onClickRemoveItem:this.handleDeleteItem}),rules:Object.values(h).filter(function(a){return a})}),summaryPrice:React.createElement(OrderSumary,{currentMode:c,modes:e,summary:g.cart.items,itemsData:g.cart.itemsData,onMouseEnterItem:this.handleMouseEnterItem,onMouseLeaveItem:this.handleMouseLeaveItem,onDeleteItem:this.handleDeleteItem,onDeleteAllItems:this.handleDeleteAllItems,onClickSelectItem:this.handleClickSelectItem}),form:React.createElement(OrderForm,{onClickSubmit:this.handleClickSubmit})})}))}}]),b}(React.PureComponent);ReactDOM.render(React.createElement(Shop,{data:data}),document.querySelector("#root-shop"));
|