mediacms/static/js/manage-media.js

1 line
12 KiB
JavaScript

!function(){"use strict";var e={7464:function(e,t,r){var n=r(2667),i=(r(7441),r(5101),r(5466)),a=r(3074),l=r.n(a),o=r(8204),s=r(4426),u=r(8349),c=r(9174),f=r(1784),d=(r(2070),r(2331));function m(e){return e.options.map((function(t){return i.createElement("div",{key:t.id,className:t.id===e.selected?"active":""},i.createElement("button",{onClick:e.onSelect,filter:e.id,value:t.id},i.createElement("span",null,t.title),t.id===e.selected?i.createElement(d.O,{type:"close"}):null))}))}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],n=!0,i=!1,a=void 0;try{for(var l,o=e[Symbol.iterator]();!(n=(l=o.next()).done)&&(r.push(l.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==o.return||o.return()}finally{if(i)throw a}}return r}}(e,t)||function(e,t){if(e){if("string"==typeof e)return g(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?g(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}m.propTypes={id:l().string.isRequired,selected:l().string.isRequired,onSelect:l().func.isRequired};var h={state:[{id:"all",title:"All"},{id:"public",title:"Public"},{id:"private",title:"Private"},{id:"unlisted",title:"Unlisted"}],media_type:[{id:"all",title:"All"},{id:"video",title:"Video"},{id:"audio",title:"Audio"},{id:"image",title:"Image"},{id:"pdf",title:"Pdf"}],encoding_status:[{id:"all",title:"All"},{id:"success",title:"Success"},{id:"running",title:"Running"},{id:"pending",title:"Pending"},{id:"fail",title:"Fail"}],reviewed:[{id:"all",title:"All"},{id:"true",title:"Yes"},{id:"false",title:"No"}],featured:[{id:"all",title:"All"},{id:"true",title:"Yes"},{id:"false",title:"No"}]};function v(e){var t=p((0,i.useState)(e.hidden),2),r=t[0],n=t[1],a=p((0,i.useState)("all"),2),l=a[0],o=a[1],u=p((0,i.useState)("all"),2),c=u[0],f=u[1],d=p((0,i.useState)("all"),2),g=d[0],v=d[1],y=p((0,i.useState)("all"),2),b=y[0],E=y[1],S=p((0,i.useState)("all"),2),_=S[0],C=S[1],w=(0,i.useRef)(null),T=(0,i.useRef)(null);function A(){r||(w.current.style.height=24+T.current.offsetHeight+"px")}function k(t){var r={state:l,media_type:c,encoding_status:g,featured:b,is_reviewed:_};switch(t.currentTarget.getAttribute("filter")){case"state":r.state=t.currentTarget.getAttribute("value"),e.onFiltersUpdate(r),o(r.state);break;case"media_type":r.media_type=t.currentTarget.getAttribute("value"),e.onFiltersUpdate(r),f(r.media_type);break;case"encoding_status":r.encoding_status=t.currentTarget.getAttribute("value"),e.onFiltersUpdate(r),v(r.encoding_status);break;case"featured":r.featured=t.currentTarget.getAttribute("value"),e.onFiltersUpdate(r),E(r.featured);break;case"reviewed":r.is_reviewed=t.currentTarget.getAttribute("value"),e.onFiltersUpdate(r),C(r.is_reviewed)}}return(0,i.useEffect)((function(){n(e.hidden),A()}),[e.hidden]),(0,i.useEffect)((function(){return s.Z.on("window_resize",A),function(){return s.Z.removeListener("window_resize",A)}}),[]),i.createElement("div",{ref:w,className:"mi-filters-row"+(r?" hidden":"")},i.createElement("div",{ref:T,className:"mi-filters-row-inner"},i.createElement("div",{className:"mi-filter"},i.createElement("div",{className:"mi-filter-title"},"STATE"),i.createElement("div",{className:"mi-filter-options"},i.createElement(m,{id:"state",options:h.state,selected:l,onSelect:k}))),i.createElement("div",{className:"mi-filter"},i.createElement("div",{className:"mi-filter-title"},"MEDIA TYPE"),i.createElement("div",{className:"mi-filter-options"},i.createElement(m,{id:"media_type",options:h.media_type,selected:c,onSelect:k}))),i.createElement("div",{className:"mi-filter"},i.createElement("div",{className:"mi-filter-title"},"ENCODING STATUS"),i.createElement("div",{className:"mi-filter-options"},i.createElement(m,{id:"encoding_status",options:h.encoding_status,selected:g,onSelect:k}))),i.createElement("div",{className:"mi-filter"},i.createElement("div",{className:"mi-filter-title"},"REVIEWED"),i.createElement("div",{className:"mi-filter-options"},i.createElement(m,{id:"reviewed",options:h.reviewed,selected:_,onSelect:k}))),i.createElement("div",{className:"mi-filter"},i.createElement("div",{className:"mi-filter-title"},"FEATURED"),i.createElement("div",{className:"mi-filter-options"},i.createElement(m,{id:"featured",options:h.featured,selected:b,onSelect:k})))))}function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function b(e){var t,r,n=(t=(0,i.useState)(e.active),r=2,function(e){if(Array.isArray(e))return e}(t)||function(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],n=!0,i=!1,a=void 0;try{for(var l,o=e[Symbol.iterator]();!(n=(l=o.next()).done)&&(r.push(l.value),!t||r.length!==t);n=!0);}catch(e){i=!0,a=e}finally{try{n||null==o.return||o.return()}finally{if(i)throw a}}return r}}(t,r)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(e,t):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),a=n[0],l=n[1];return i.createElement("div",{className:"mi-filters-toggle"},i.createElement("button",{className:a?"active":"","aria-label":"Filter",onClick:function(){l(!a),void 0!==e.onClick&&e.onClick()}},i.createElement(d.O,{type:"filter_list"}),i.createElement("span",{className:"filter-button-label"},i.createElement("span",{className:"filter-button-label-text"},"FILTERS"))))}function E(e){return(E="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function S(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _(e,t){return(_=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function C(e,t){return!t||"object"!==E(t)&&"function"!=typeof t?w(e):t}function w(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function T(e){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function A(e,t,r,n){return e+"?"+t+(""===t?"":"&")+r+(""===r?"":"&")+"page="+n}v.propTypes={hidden:l().bool},v.defaultProps={hidden:!1},b.propTypes={onClick:l().func,active:l().bool},b.defaultProps={active:!1};var k=function(e){!function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_(e,t)}(o,e);var t,r,n,a,l=(n=o,a=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}(),function(){var e,t=T(n);if(a){var r=T(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return C(this,e)});function o(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,o),(t=l.call(this,e,"manage-media")).state={resultsCount:null,currentPage:1,requestUrl:e.api_url,pageTitle:e.title,hiddenFilters:!0,filterArgs:"",sortingArgs:"",sortBy:"add_date",ordering:"desc",refresh:0},t.getCountFunc=t.getCountFunc.bind(w(t)),t.onTablePageChange=t.onTablePageChange.bind(w(t)),t.onToggleFiltersClick=t.onToggleFiltersClick.bind(w(t)),t.onFiltersUpdate=t.onFiltersUpdate.bind(w(t)),t.onColumnSortClick=t.onColumnSortClick.bind(w(t)),t.onItemsRemoval=t.onItemsRemoval.bind(w(t)),t.onItemsRemovalFail=t.onItemsRemovalFail.bind(w(t)),t}return t=o,(r=[{key:"onTablePageChange",value:function(e,t){this.setState({currentPage:t,requestUrl:A(this.props.api_url,this.state.filterArgs,this.state.sortingArgs,t)})}},{key:"onToggleFiltersClick",value:function(){this.setState({hiddenFilters:!this.state.hiddenFilters})}},{key:"getCountFunc",value:function(e){this.setState({resultsCount:e,pageTitle:this.state.pageTitle})}},{key:"onFiltersUpdate",value:function(e){var t=[];for(var r in e)null!==e[r]&&"all"!==e[r]&&t.push(r+"="+e[r]);this.setState({filterArgs:t.join("&"),requestUrl:A(this.props.api_url,t.join("&"),this.state.sortingArgs,this.state.currentPage)})}},{key:"onColumnSortClick",value:function(e,t){var r="sort_by="+e+"&ordering="+t;this.setState({sortBy:e,ordering:t,sortingArgs:r,requestUrl:A(this.props.api_url,this.state.filterArgs,r,this.state.currentPage)})}},{key:"onItemsRemoval",value:function(e){this.setState({resultsCount:null,refresh:this.state.refresh+1,requestUrl:this.props.api_url},(function(){u.wN("The media deleted successfully.","mediaRemovalSucceed")}))}},{key:"onItemsRemovalFail",value:function(e){u.wN("The media removal failed. Please try again.","mediaRemovalFailed")}},{key:"pageContent",value:function(){return i.createElement(c._,{title:this.state.pageTitle+(null===this.state.resultsCount?"":" ("+this.state.resultsCount+")"),className:""},i.createElement(b,{onClick:this.onToggleFiltersClick}),i.createElement(v,{hidden:this.state.hiddenFilters,onFiltersUpdate:this.onFiltersUpdate}),i.createElement(f.x,{pageItems:50,manageType:"media",key:this.state.requestUrl+"["+this.state.refresh+"]",requestUrl:this.state.requestUrl,itemsCountCallback:this.getCountFunc,onPageChange:this.onTablePageChange,sortBy:this.state.sortBy,ordering:this.state.ordering,onRowsDelete:this.onItemsRemoval,onRowsDeleteFail:this.onItemsRemovalFail,onClickColumnSort:this.onColumnSortClick}))}}])&&S(t.prototype,r),o}(o.T);k.propTypes={title:l().string.isRequired,api_url:l().string.isRequired},k.defaultProps={title:"Manage media",api_url:s.Z.get("api-manage-media")},(0,n.X)("page-manage-media",k)}},t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={exports:{}};return e[n].call(i.exports,i,i.exports,r),i.exports}r.m=e,r.x=function(){},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.j=441,function(){var e={441:0},t=[[7464,431]],n=function(){},i=function(i,a){for(var l,o,s=a[0],u=a[1],c=a[2],f=a[3],d=0,m=[];d<s.length;d++)o=s[d],r.o(e,o)&&e[o]&&m.push(e[o][0]),e[o]=0;for(l in u)r.o(u,l)&&(r.m[l]=u[l]);for(c&&c(r),i&&i(a);m.length;)m.shift()();return f&&t.push.apply(t,f),n()},a=self.webpackChunk_mediacms_frontend=self.webpackChunk_mediacms_frontend||[];function l(){for(var n,i=0;i<t.length;i++){for(var a=t[i],l=!0,o=1;o<a.length;o++){var s=a[o];0!==e[s]&&(l=!1)}l&&(t.splice(i--,1),n=r(r.s=a[0]))}return 0===t.length&&(r.x(),r.x=function(){}),n}a.forEach(i.bind(null,0)),a.push=i.bind(null,a.push.bind(a));var o=r.x;r.x=function(){return r.x=o||function(){},(n=l)()}}(),r.x()}();