diff --git a/bootstrap.php b/bootstrap.php deleted file mode 100644 index aec6c04..0000000 --- a/bootstrap.php +++ /dev/null @@ -1,12 +0,0 @@ -subscribe(Listeners\AddDiscussionViewHandler::class); - $events->subscribe(Listeners\AddAssets::class); - $events->subscribe(Listeners\AddDiscussionApiAttributes::class); - $events->subscribe(Listeners\AddPopularSort::class); - $events->subscribe(Listeners\SaveDiscussionFromModal::class); -}; diff --git a/composer.json b/composer.json index 5742471..65bb8c3 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Add views to flarum discussions", "type": "flarum-extension", "require": { - "flarum/core": "^0.1.0-beta.7" + "flarum/core": "^0.1.0-beta.8" }, "license": "MIT", "authors": [ @@ -25,10 +25,13 @@ "flarum-extension": { "title": "Discussion views", "icon": { - "name": "eye", + "name": "far fa-eye", "backgroundColor": "#88CC23", "color": "#fff" } + }, + "flagrow": { + "discuss": "https://discuss.flarum.org/d/7339" } } } \ No newline at end of file diff --git a/extend.php b/extend.php new file mode 100644 index 0000000..b2173ec --- /dev/null +++ b/extend.php @@ -0,0 +1,24 @@ +css(__DIR__ . '/less/extension.less') + ->js(__DIR__. '/js/dist/forum.js'), + + (new Frontend('admin')) + ->js(__DIR__ . '/js/dist/admin.js'), + + new Locales(__DIR__ . '/locale'), + + function (Dispatcher $events) { + $events->subscribe(Listeners\AddDiscussionViewHandler::class); + $events->subscribe(Listeners\AddDiscussionApiAttributes::class); + $events->subscribe(Listeners\AddPopularSort::class); + $events->subscribe(Listeners\SaveDiscussionFromModal::class); + } +]; diff --git a/js/admin.js b/js/admin.js new file mode 100644 index 0000000..13dc041 --- /dev/null +++ b/js/admin.js @@ -0,0 +1 @@ +export * from './src/admin'; \ No newline at end of file diff --git a/js/admin/Gulpfile.js b/js/admin/Gulpfile.js deleted file mode 100644 index 6c4b0bb..0000000 --- a/js/admin/Gulpfile.js +++ /dev/null @@ -1,7 +0,0 @@ -var flarum = require('flarum-gulp'); - -flarum({ - modules: { - 'michaelbelgium/flarum-discussion-views': 'src/**/*.js' - } -}); \ No newline at end of file diff --git a/js/admin/dist/extension.js b/js/admin/dist/extension.js deleted file mode 100644 index c28fecb..0000000 --- a/js/admin/dist/extension.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/main', ['flarum/extend', 'flarum/app', 'flarum/components/PermissionGrid'], function (_export, _context) { - "use strict"; - - var extend, app, PermissionGrid; - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumApp) { - app = _flarumApp.default; - }, function (_flarumComponentsPermissionGrid) { - PermissionGrid = _flarumComponentsPermissionGrid.default; - }], - execute: function () { - - app.initializers.add('michaelbelgium-admin-discussion-views', function () { - extend(PermissionGrid.prototype, 'moderateItems', function (items) { - items.add('resetViews', { - icon: 'eye', - label: app.translator.trans('flarum_discussion_views.admin.permissions.reset_views_label'), - permission: 'discussion.resetViews' - }); - }); - }); - } - }; -}); \ No newline at end of file diff --git a/js/admin/package.json b/js/admin/package.json deleted file mode 100644 index 6216d68..0000000 --- a/js/admin/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "private": true, - "devDependencies": { - "flarum-gulp": "^0.2.0", - "gulp": "^3.9.1" - } -} diff --git a/js/dist/admin.js b/js/dist/admin.js new file mode 100644 index 0000000..6e5246f --- /dev/null +++ b/js/dist/admin.js @@ -0,0 +1,2 @@ +module.exports=function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=12)}([function(e,t){e.exports=flarum.core.compat.extend},function(e,t){e.exports=flarum.core.compat.app},,,,,,,,,function(e,t){e.exports=flarum.core.compat["components/PermissionGrid"]},,function(e,t,r){"use strict";r.r(t);var n=r(0),o=r(1),i=r.n(o),u=r(10),s=r.n(u);i.a.initializers.add("michaelbelgium-admin-discussion-views",function(){Object(n.extend)(s.a.prototype,"moderateItems",function(e){e.add("resetViews",{icon:"far fa-eye",label:i.a.translator.trans("flarum_discussion_views.admin.permissions.reset_views_label"),permission:"discussion.resetViews"})})})}]); +//# sourceMappingURL=admin.js.map \ No newline at end of file diff --git a/js/dist/admin.js.map b/js/dist/admin.js.map new file mode 100644 index 0000000..5d64ca6 --- /dev/null +++ b/js/dist/admin.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://@michaelbelgium/flarum-discussion-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['components/PermissionGrid']\"","webpack://@michaelbelgium/flarum-discussion-views/./src/admin/index.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","app","initializers","add","extend","PermissionGrid","items","icon","label","translator","trans","permission"],"mappings":"2BACA,IAAAA,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF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AhC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,sBCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,2BCAAnC,EAAAD,QAAAkC,OAAAC,KAAAC,OAAA,+GCIAC,IAAIC,aAAaC,IAAI,wCAAyC,WAC7DC,iBAAOC,IAAeX,UAAW,gBAAiB,SAAAY,GACjDA,EAAMH,IAAI,aAAc,CACvBI,KAAM,aACNC,MAAOP,IAAIQ,WAAWC,MAAM,+DAC5BC,WAAY","file":"admin.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 12);\n","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['components/PermissionGrid'];","import { extend } from 'flarum/extend';\r\nimport app from 'flarum/app';\r\nimport PermissionGrid from 'flarum/components/PermissionGrid';\r\n\r\napp.initializers.add('michaelbelgium-admin-discussion-views', () => {\r\n\textend(PermissionGrid.prototype, 'moderateItems', items => {\r\n\t\titems.add('resetViews', {\r\n\t\t\ticon: 'far fa-eye',\r\n\t\t\tlabel: app.translator.trans('flarum_discussion_views.admin.permissions.reset_views_label'),\r\n\t\t\tpermission: 'discussion.resetViews'\r\n\t\t});\r\n\t});\r\n});\r\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/dist/forum.js b/js/dist/forum.js new file mode 100644 index 0000000..824ebdd --- /dev/null +++ b/js/dist/forum.js @@ -0,0 +1,2 @@ +module.exports=function(t){var o={};function e(n){if(o[n])return o[n].exports;var r=o[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,e),r.l=!0,r.exports}return e.m=t,e.c=o,e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,o){if(1&o&&(t=e(t)),8&o)return t;if(4&o&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&o&&"string"!=typeof t)for(var r in t)e.d(n,r,function(o){return t[o]}.bind(null,r));return n},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,o){return Object.prototype.hasOwnProperty.call(t,o)},e.p="",e(e.s=11)}([function(t,o){t.exports=flarum.core.compat.extend},function(t,o){t.exports=flarum.core.compat.app},function(t,o){t.exports=flarum.core.compat["components/Button"]},function(t,o){t.exports=flarum.core.compat.Model},function(t,o){t.exports=flarum.core.compat["models/Discussion"]},function(t,o){t.exports=flarum.core.compat["utils/DiscussionControls"]},function(t,o){t.exports=flarum.core.compat["components/DiscussionList"]},function(t,o){t.exports=flarum.core.compat["components/DiscussionListItem"]},function(t,o){t.exports=flarum.core.compat["utils/abbreviateNumber"]},function(t,o){t.exports=flarum.core.compat["components/Modal"]},,function(t,o,e){"use strict";e.r(o);var n=e(1),r=e.n(n),s=e(0),i=e(6),u=e.n(i),a=e(3),c=e.n(a),p=e(4),l=e.n(p),f=e(7),d=e.n(f),v=e(8),b=e.n(v),w=e(2),h=e.n(w),y=e(5),_=e.n(y);var x=e(9),g=function(t){var o,e;function n(){return t.apply(this,arguments)||this}e=t,(o=n).prototype=Object.create(e.prototype),o.prototype.constructor=o,o.__proto__=e;var r=n.prototype;return r.init=function(){t.prototype.init.call(this),this.discussion=this.props.discussion,this.currentViewsCount=this.props.discussion.views(),this.newViewsCount=m.prop(this.currentViewsCount)},r.content=function(){return m("div",{className:"Modal-body"},m("div",{className:"Form Form--centered"},m("div",{className:"Form-group"},m("label",null,app.translator.trans("flarum_discussion_views.forum.modal_resetviews.label")),m("input",{className:"FormControl",type:"number",min:"0",bidi:this.newViewsCount})),m("div",{className:"Form-group"},h.a.component({className:"Button Button--primary Button--block",type:"submit",loading:this.loading,children:app.translator.trans("flarum_discussion_views.forum.modal_resetviews.submit")}))))},r.title=function(){return app.translator.trans("flarum_discussion_views.forum.modal_resetviews.title")},r.className=function(){return"Modal--small"},r.onsubmit=function(t){var o=this;t.preventDefault(),this.loading=!0;var e=parseInt(this.newViewsCount()),n=this.currentViewsCount;e>=0&&e!==n&&this.props.discussion.save({views:e}).then(function(){m.redraw()}).catch(function(t){o.loading=!1,console.log(t)}),this.hide()},n}(e.n(x).a);r.a.initializers.add("michaelbelgium-discussion-views",function(){Object(s.extend)(u.a.prototype,"sortMap",function(t){t.popular="-view_count",t.unpopular="view_count"}),l.a.prototype.views=c.a.attribute("views"),l.a.prototype.canReset=c.a.attribute("canReset"),Object(s.extend)(d.a.prototype,"infoItems",function(t){var o=this.props.discussion;t.add("discussion-views",b()(o.views()))}),Object(s.extend)(_.a,"moderationControls",function(t,o){o.canReset()&&t.add("reset",h.a.component({children:app.translator.trans("flarum_discussion_views.forum.discussion_controls.resetviews_button"),icon:"far fa-eye",onclick:this.resetViewsAction.bind(o)}))}),_.a.resetViewsAction=function(){return app.modal.show(new g({discussion:this}))}})}]); +//# sourceMappingURL=forum.js.map \ No newline at end of file diff --git a/js/dist/forum.js.map b/js/dist/forum.js.map new file mode 100644 index 0000000..753eaaa --- /dev/null +++ b/js/dist/forum.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://@michaelbelgium/flarum-discussion-views/webpack/bootstrap","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['extend']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['app']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['components/Button']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['Model']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['models/Discussion']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['utils/DiscussionControls']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['components/DiscussionList']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['components/DiscussionListItem']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['utils/abbreviateNumber']\"","webpack://@michaelbelgium/flarum-discussion-views/external \"flarum.core.compat['components/Modal']\"","webpack://@michaelbelgium/flarum-discussion-views/./src/forum/components/ResetDiscussionViewsModal.js","webpack://@michaelbelgium/flarum-discussion-views/./node_modules/@babel/runtime/helpers/esm/inheritsLoose.js","webpack://@michaelbelgium/flarum-discussion-views/./src/forum/index.js","webpack://@michaelbelgium/flarum-discussion-views/./src/forum/components/AddPopularSort.js","webpack://@michaelbelgium/flarum-discussion-views/./src/forum/components/AddViewsToModelAndDisplay.js","webpack://@michaelbelgium/flarum-discussion-views/./src/forum/components/AddModerationControl.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","flarum","core","compat","ResetDiscussionViewsModal","subClass","superClass","constructor","__proto__","init","_Modal","this","discussion","props","currentViewsCount","views","newViewsCount","prop","content","className","app","translator","trans","type","min","bidi","Button","component","loading","children","title","onsubmit","e","_this","preventDefault","newViews","parseInt","currentViews","save","then","redraw","catch","reason","console","log","hide","Modal","initializers","add","extend","DiscussionList","map","popular","unpopular","Discussion","Model","attribute","canReset","DiscussionListItem","items","abbreviateNumber","DiscussionControls","icon","onclick","resetViewsAction","modal","show"],"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2DAGhCH,qBAEI,MAAO,kBAGXY,kBAASC,GACT,IAAAC,EAAAtB,KACIqB,EAAEE,iBACFvB,KAAKiB,SAAU,EAEf,IAAMO,EAAWC,SAASzB,KAAKK,iBACzBqB,EAAe1B,KAAKG,kBAEtBqB,GAAY,GAAKA,IAAaE,GAE9B1B,KAAKE,MAAMD,WACN0B,KAAK,CAAEvB,MAAOoB,IACdI,KAAK,WAAQlE,EAAEmE,WACfC,MAAM,SAACC,GACJT,EAAKL,SAAU,EACfe,QAAQC,IAAIF,KAIxB/B,KAAKkC,kBA7D0CC,GEEvD1B,IAAI2B,aAAaC,IAAI,kCAAmC,WCDpDC,iBAAOC,IAAerD,UAAW,UAAW,SAAUsD,GAClDA,EAAIC,QAAU,cACdD,EAAIE,UAAY,eCCpBC,IAAWzD,UAAUkB,MAAQwC,IAAMC,UAAU,SAC7CF,IAAWzD,UAAU4D,SAAWF,IAAMC,UAAU,YAEhDP,iBAAOS,IAAmB7D,UAAW,YAAa,SAAS8D,GACvD,IAAM/C,EAAaD,KAAKE,MAAMD,WAC9B+C,EAAMX,IAAI,mBAAoBY,IAAiBhD,EAAWG,YCN9DkC,iBAAOY,IAAoB,qBAAsB,SAASF,EAAO/C,GAC1DA,EAAW6C,YAEVE,EAAMX,IAAI,QAAStB,IAAOC,UAAU,CAChCE,SAAUT,IAAIC,WAAWC,MAAM,uEAC/BwC,KAAM,aACNC,QAASpD,KAAKqD,iBAAiBvE,KAAKmB,QAKhDiD,IAAmBG,iBAAmB,WAClC,OAAO5C,IAAI6C,MAAMC,KAAK,IAAI9D,EAA0B,CAChDQ,WAAYD","file":"forum.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 11);\n","module.exports = flarum.core.compat['extend'];","module.exports = flarum.core.compat['app'];","module.exports = flarum.core.compat['components/Button'];","module.exports = flarum.core.compat['Model'];","module.exports = flarum.core.compat['models/Discussion'];","module.exports = flarum.core.compat['utils/DiscussionControls'];","module.exports = flarum.core.compat['components/DiscussionList'];","module.exports = flarum.core.compat['components/DiscussionListItem'];","module.exports = flarum.core.compat['utils/abbreviateNumber'];","module.exports = flarum.core.compat['components/Modal'];","import Modal from 'flarum/components/Modal';\r\nimport Button from 'flarum/components/Button';\r\n\r\nexport default class ResetDiscussionViewsModal extends Modal {\r\n init()\r\n {\r\n super.init();\r\n\r\n this.discussion = this.props.discussion;\r\n this.currentViewsCount = this.props.discussion.views();\r\n this.newViewsCount = m.prop(this.currentViewsCount);\r\n }\r\n\r\n content()\r\n {\r\n return (\r\n
\r\n
\r\n
\r\n \r\n \r\n
\r\n
\r\n {Button.component({\r\n className: 'Button Button--primary Button--block',\r\n type: 'submit',\r\n loading: this.loading,\r\n children: app.translator.trans('flarum_discussion_views.forum.modal_resetviews.submit')\r\n })}\r\n
\r\n
\r\n
\r\n )\r\n }\r\n\r\n title()\r\n {\r\n return app.translator.trans('flarum_discussion_views.forum.modal_resetviews.title');\r\n }\r\n\r\n className()\r\n {\r\n return 'Modal--small';\r\n }\r\n\r\n onsubmit(e)\r\n {\r\n e.preventDefault();\r\n this.loading = true;\r\n\r\n const newViews = parseInt(this.newViewsCount());\r\n const currentViews = this.currentViewsCount;\r\n\r\n if (newViews >= 0 && newViews !== currentViews)\r\n {\r\n this.props.discussion\r\n .save({ views: newViews })\r\n .then(() => { m.redraw(); })\r\n .catch((reason) => {\r\n this.loading = false;\r\n console.log(reason)\r\n });\r\n }\r\n\r\n this.hide();\r\n }\r\n}\r\n","export default function _inheritsLoose(subClass, superClass) {\n subClass.prototype = Object.create(superClass.prototype);\n subClass.prototype.constructor = subClass;\n subClass.__proto__ = superClass;\n}","import app from 'flarum/app';\r\nimport AddPopularSort from './components/AddPopularSort';\r\nimport AddViewsToModelAndDisplay from './components/AddViewsToModelAndDisplay';\r\nimport AddModerationControl from './components/AddModerationControl';\r\n\r\napp.initializers.add('michaelbelgium-discussion-views', function () {\r\n AddPopularSort();\r\n AddViewsToModelAndDisplay();\r\n AddModerationControl();\r\n});\r\n","import { extend } from 'flarum/extend';\r\nimport DiscussionList from 'flarum/components/DiscussionList';\r\n\r\nexport default function () {\r\n extend(DiscussionList.prototype, 'sortMap', function (map) {\r\n map.popular = '-view_count';\r\n map.unpopular = 'view_count';\r\n });\r\n}\r\n","import { extend } from 'flarum/extend';\r\nimport Model from 'flarum/Model';\r\nimport Discussion from 'flarum/models/Discussion';\r\nimport DiscussionListItem from 'flarum/components/DiscussionListItem';\r\nimport abbreviateNumber from 'flarum/utils/abbreviateNumber';\r\n\r\nexport default function () {\r\n Discussion.prototype.views = Model.attribute('views');\r\n Discussion.prototype.canReset = Model.attribute('canReset');\r\n\r\n extend(DiscussionListItem.prototype, 'infoItems', function(items) {\r\n const discussion = this.props.discussion;\r\n items.add('discussion-views', abbreviateNumber(discussion.views()));\r\n });\r\n}\r\n","import { extend } from 'flarum/extend';\r\nimport Button from 'flarum/components/Button';\r\nimport DiscussionControls from 'flarum/utils/DiscussionControls';\r\nimport ResetDiscussionViewsModal from './ResetDiscussionViewsModal';\r\n\r\nexport default function () {\r\n extend(DiscussionControls, 'moderationControls', function(items, discussion) {\r\n if(discussion.canReset())\r\n {\r\n items.add('reset', Button.component({\r\n children: app.translator.trans('flarum_discussion_views.forum.discussion_controls.resetviews_button'),\r\n icon: 'far fa-eye',\r\n onclick: this.resetViewsAction.bind(discussion)\r\n }));\r\n }\r\n });\r\n\r\n DiscussionControls.resetViewsAction = function() {\r\n return app.modal.show(new ResetDiscussionViewsModal({\r\n discussion: this\r\n }));\r\n };\r\n}\r\n"],"sourceRoot":""} \ No newline at end of file diff --git a/js/forum.js b/js/forum.js new file mode 100644 index 0000000..facb26f --- /dev/null +++ b/js/forum.js @@ -0,0 +1 @@ +export * from './src/forum'; diff --git a/js/forum/Gulpfile.js b/js/forum/Gulpfile.js deleted file mode 100644 index 6c4b0bb..0000000 --- a/js/forum/Gulpfile.js +++ /dev/null @@ -1,7 +0,0 @@ -var flarum = require('flarum-gulp'); - -flarum({ - modules: { - 'michaelbelgium/flarum-discussion-views': 'src/**/*.js' - } -}); \ No newline at end of file diff --git a/js/forum/dist/extension.js b/js/forum/dist/extension.js deleted file mode 100644 index 07f673c..0000000 --- a/js/forum/dist/extension.js +++ /dev/null @@ -1,221 +0,0 @@ -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/components/AddModerationControl', ['flarum/extend', 'flarum/components/Button', 'flarum/utils/DiscussionControls', 'michaelbelgium/flarum-discussion-views/components/ResetDiscussionViewsModal'], function (_export, _context) { - "use strict"; - - var extend, Button, DiscussionControls, ResetDiscussionViewsModal; - - _export('default', function () { - extend(DiscussionControls, 'moderationControls', function (items, discussion) { - if (discussion.canReset()) { - items.add('reset', Button.component({ - children: app.translator.trans('flarum_discussion_views.forum.discussion_controls.resetviews_button'), - icon: 'eye', - onclick: this.resetViewsAction.bind(discussion) - })); - } - }); - - DiscussionControls.resetViewsAction = function () { - return app.modal.show(new ResetDiscussionViewsModal({ - discussion: this - })); - }; - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsButton) { - Button = _flarumComponentsButton.default; - }, function (_flarumUtilsDiscussionControls) { - DiscussionControls = _flarumUtilsDiscussionControls.default; - }, function (_michaelbelgiumFlarumDiscussionViewsComponentsResetDiscussionViewsModal) { - ResetDiscussionViewsModal = _michaelbelgiumFlarumDiscussionViewsComponentsResetDiscussionViewsModal.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/components/AddPopularSort', ['flarum/extend', 'flarum/components/DiscussionList'], function (_export, _context) { - "use strict"; - - var extend, DiscussionList; - - _export('default', function () { - extend(DiscussionList.prototype, 'sortMap', function (map) { - map.popular = '-views'; - map.unpopular = 'views'; - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumComponentsDiscussionList) { - DiscussionList = _flarumComponentsDiscussionList.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/components/AddViewsToModelAndDisplay', ['flarum/extend', 'flarum/Model', 'flarum/models/Discussion', 'flarum/components/DiscussionListItem', 'flarum/utils/abbreviateNumber'], function (_export, _context) { - "use strict"; - - var extend, Model, Discussion, DiscussionListItem, abbreviateNumber; - - _export('default', function () { - Discussion.prototype.views = Model.attribute('views'); - Discussion.prototype.canReset = Model.attribute('canReset'); - - extend(DiscussionListItem.prototype, 'infoItems', function (items) { - var discussion = this.props.discussion; - items.add('discussion-views', abbreviateNumber(discussion.views())); - }); - }); - - return { - setters: [function (_flarumExtend) { - extend = _flarumExtend.extend; - }, function (_flarumModel) { - Model = _flarumModel.default; - }, function (_flarumModelsDiscussion) { - Discussion = _flarumModelsDiscussion.default; - }, function (_flarumComponentsDiscussionListItem) { - DiscussionListItem = _flarumComponentsDiscussionListItem.default; - }, function (_flarumUtilsAbbreviateNumber) { - abbreviateNumber = _flarumUtilsAbbreviateNumber.default; - }], - execute: function () {} - }; -});; -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/components/ResetDiscussionViewsModal', ['flarum/components/Modal', 'flarum/components/Button'], function (_export, _context) { - "use strict"; - - var Modal, Button, ResetDiscussionViewsModal; - return { - setters: [function (_flarumComponentsModal) { - Modal = _flarumComponentsModal.default; - }, function (_flarumComponentsButton) { - Button = _flarumComponentsButton.default; - }], - execute: function () { - ResetDiscussionViewsModal = function (_Modal) { - babelHelpers.inherits(ResetDiscussionViewsModal, _Modal); - - function ResetDiscussionViewsModal() { - babelHelpers.classCallCheck(this, ResetDiscussionViewsModal); - return babelHelpers.possibleConstructorReturn(this, (ResetDiscussionViewsModal.__proto__ || Object.getPrototypeOf(ResetDiscussionViewsModal)).apply(this, arguments)); - } - - babelHelpers.createClass(ResetDiscussionViewsModal, [{ - key: 'init', - value: function init() { - babelHelpers.get(ResetDiscussionViewsModal.prototype.__proto__ || Object.getPrototypeOf(ResetDiscussionViewsModal.prototype), 'init', this).call(this); - - this.discussion = this.props.discussion; - this.currentViewsCount = this.props.discussion.views(); - this.newViewsCount = m.prop(this.currentViewsCount); - } - }, { - key: 'content', - value: function content() { - return m( - 'div', - { className: 'Modal-body' }, - m( - 'div', - { className: 'Form Form--centered' }, - m( - 'div', - { className: 'Form-group' }, - m( - 'label', - null, - app.translator.trans('flarum_discussion_views.forum.modal_resetviews.label') - ), - m('input', { className: 'FormControl', type: 'number', min: '0', bidi: this.newViewsCount }) - ), - m( - 'div', - { className: 'Form-group' }, - Button.component({ - className: 'Button Button--primary Button--block', - type: 'submit', - loading: this.loading, - children: app.translator.trans('flarum_discussion_views.forum.modal_resetviews.submit') - }) - ) - ) - ); - } - }, { - key: 'title', - value: function title() { - return app.translator.trans('flarum_discussion_views.forum.modal_resetviews.title'); - } - }, { - key: 'className', - value: function className() { - return 'Modal--small'; - } - }, { - key: 'onsubmit', - value: function onsubmit(e) { - var _this2 = this; - - e.preventDefault(); - this.loading = true; - - var newViews = parseInt(this.newViewsCount()); - var currentViews = this.currentViewsCount; - - if (newViews >= 0 && newViews !== currentViews) { - this.props.discussion.save({ views: newViews }).then(function () { - m.redraw(); - }).catch(function (reason) { - _this2.loading = false; - console.log(reason); - }); - } - - this.hide(); - } - }]); - return ResetDiscussionViewsModal; - }(Modal); - - _export('default', ResetDiscussionViewsModal); - } - }; -});; -'use strict'; - -System.register('michaelbelgium/flarum-discussion-views/main', ['flarum/app', 'michaelbelgium/flarum-discussion-views/components/AddPopularSort', 'michaelbelgium/flarum-discussion-views/components/AddViewsToModelAndDisplay', 'michaelbelgium/flarum-discussion-views/components/AddModerationControl'], function (_export, _context) { - "use strict"; - - var app, AddPopularSort, AddViewsToModelAndDisplay, AddModerationControl; - return { - setters: [function (_flarumApp) { - app = _flarumApp.default; - }, function (_michaelbelgiumFlarumDiscussionViewsComponentsAddPopularSort) { - AddPopularSort = _michaelbelgiumFlarumDiscussionViewsComponentsAddPopularSort.default; - }, function (_michaelbelgiumFlarumDiscussionViewsComponentsAddViewsToModelAndDisplay) { - AddViewsToModelAndDisplay = _michaelbelgiumFlarumDiscussionViewsComponentsAddViewsToModelAndDisplay.default; - }, function (_michaelbelgiumFlarumDiscussionViewsComponentsAddModerationControl) { - AddModerationControl = _michaelbelgiumFlarumDiscussionViewsComponentsAddModerationControl.default; - }], - execute: function () { - - app.initializers.add('michaelbelgium-discussion-views', function () { - AddPopularSort(); - AddViewsToModelAndDisplay(); - AddModerationControl(); - }); - } - }; -}); \ No newline at end of file diff --git a/js/forum/package.json b/js/forum/package.json deleted file mode 100644 index 6216d68..0000000 --- a/js/forum/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "private": true, - "devDependencies": { - "flarum-gulp": "^0.2.0", - "gulp": "^3.9.1" - } -} diff --git a/js/forum/src/main.js b/js/forum/src/main.js deleted file mode 100644 index 2cf3799..0000000 --- a/js/forum/src/main.js +++ /dev/null @@ -1,10 +0,0 @@ -import app from 'flarum/app'; -import AddPopularSort from 'michaelbelgium/flarum-discussion-views/components/AddPopularSort'; -import AddViewsToModelAndDisplay from 'michaelbelgium/flarum-discussion-views/components/AddViewsToModelAndDisplay'; -import AddModerationControl from 'michaelbelgium/flarum-discussion-views/components/AddModerationControl'; - -app.initializers.add('michaelbelgium-discussion-views', function () { - AddPopularSort(); - AddViewsToModelAndDisplay(); - AddModerationControl(); -}); diff --git a/js/package.json b/js/package.json new file mode 100644 index 0000000..c983719 --- /dev/null +++ b/js/package.json @@ -0,0 +1,13 @@ +{ + "private": true, + "name": "@michaelbelgium/flarum-discussion-views", + "dependencies": { + "flarum-webpack-config": "0.1.0-beta.10", + "webpack": "^4.0.0", + "webpack-cli": "^3.0.7" + }, + "scripts": { + "dev": "webpack --mode development --watch", + "build": "webpack --mode production" + } +} diff --git a/js/admin/src/main.js b/js/src/admin/index.js similarity index 95% rename from js/admin/src/main.js rename to js/src/admin/index.js index 22907cf..6060b7c 100644 --- a/js/admin/src/main.js +++ b/js/src/admin/index.js @@ -5,7 +5,7 @@ import PermissionGrid from 'flarum/components/PermissionGrid'; app.initializers.add('michaelbelgium-admin-discussion-views', () => { extend(PermissionGrid.prototype, 'moderateItems', items => { items.add('resetViews', { - icon: 'eye', + icon: 'far fa-eye', label: app.translator.trans('flarum_discussion_views.admin.permissions.reset_views_label'), permission: 'discussion.resetViews' }); diff --git a/js/forum/src/components/AddModerationControl.js b/js/src/forum/components/AddModerationControl.js similarity index 83% rename from js/forum/src/components/AddModerationControl.js rename to js/src/forum/components/AddModerationControl.js index e4a11bb..4b5e41f 100644 --- a/js/forum/src/components/AddModerationControl.js +++ b/js/src/forum/components/AddModerationControl.js @@ -1,7 +1,7 @@ import { extend } from 'flarum/extend'; import Button from 'flarum/components/Button'; import DiscussionControls from 'flarum/utils/DiscussionControls'; -import ResetDiscussionViewsModal from 'michaelbelgium/flarum-discussion-views/components/ResetDiscussionViewsModal'; +import ResetDiscussionViewsModal from './ResetDiscussionViewsModal'; export default function () { extend(DiscussionControls, 'moderationControls', function(items, discussion) { @@ -9,7 +9,7 @@ export default function () { { items.add('reset', Button.component({ children: app.translator.trans('flarum_discussion_views.forum.discussion_controls.resetviews_button'), - icon: 'eye', + icon: 'far fa-eye', onclick: this.resetViewsAction.bind(discussion) })); } diff --git a/js/forum/src/components/AddPopularSort.js b/js/src/forum/components/AddPopularSort.js similarity index 73% rename from js/forum/src/components/AddPopularSort.js rename to js/src/forum/components/AddPopularSort.js index 5192295..2ee43a0 100644 --- a/js/forum/src/components/AddPopularSort.js +++ b/js/src/forum/components/AddPopularSort.js @@ -3,7 +3,7 @@ import DiscussionList from 'flarum/components/DiscussionList'; export default function () { extend(DiscussionList.prototype, 'sortMap', function (map) { - map.popular = '-views'; - map.unpopular = 'views'; + map.popular = '-view_count'; + map.unpopular = 'view_count'; }); } diff --git a/js/forum/src/components/AddViewsToModelAndDisplay.js b/js/src/forum/components/AddViewsToModelAndDisplay.js similarity index 100% rename from js/forum/src/components/AddViewsToModelAndDisplay.js rename to js/src/forum/components/AddViewsToModelAndDisplay.js diff --git a/js/forum/src/components/ResetDiscussionViewsModal.js b/js/src/forum/components/ResetDiscussionViewsModal.js similarity index 100% rename from js/forum/src/components/ResetDiscussionViewsModal.js rename to js/src/forum/components/ResetDiscussionViewsModal.js diff --git a/js/src/forum/index.js b/js/src/forum/index.js new file mode 100644 index 0000000..f56c485 --- /dev/null +++ b/js/src/forum/index.js @@ -0,0 +1,10 @@ +import app from 'flarum/app'; +import AddPopularSort from './components/AddPopularSort'; +import AddViewsToModelAndDisplay from './components/AddViewsToModelAndDisplay'; +import AddModerationControl from './components/AddModerationControl'; + +app.initializers.add('michaelbelgium-discussion-views', function () { + AddPopularSort(); + AddViewsToModelAndDisplay(); + AddModerationControl(); +}); diff --git a/js/webpack.config.js b/js/webpack.config.js new file mode 100644 index 0000000..fa68b09 --- /dev/null +++ b/js/webpack.config.js @@ -0,0 +1,3 @@ +const config = require('flarum-webpack-config'); + +module.exports = config(); \ No newline at end of file diff --git a/less/extension.less b/less/extension.less index ea0e82e..f09919a 100644 --- a/less/extension.less +++ b/less/extension.less @@ -2,7 +2,6 @@ font-size: 14px; float:right; width: 10px; - margin-top: 10px; margin-right: -46px; } @@ -10,29 +9,19 @@ { .item-discussion-views:before { display: inline-block; - font: normal normal normal 14px/1 FontAwesome; + font-family: 'Font Awesome 5 Free'; font-size: inherit; text-rendering: auto; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; content: "\f06e"; float: left; margin-left: -21px; - margin-top: 3px; + margin-top: 1px; } } @media (max-width: 767px) { .item-discussion-views { - background: #e8ecf3; - color: #667c99; - border-radius: 4px; - font-size: 12px; - padding: 2px 6px; - position: absolute; - right: 100px; - top: 2px; - width: auto; + display: none; } } \ No newline at end of file diff --git a/migrations/2017_11_07_223624_discussions_add_views.php b/migrations/2017_11_07_223624_discussions_add_views.php index 472d698..54cb6ee 100644 --- a/migrations/2017_11_07_223624_discussions_add_views.php +++ b/migrations/2017_11_07_223624_discussions_add_views.php @@ -1,18 +1,7 @@ function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->integer('views')->default(0); - }); - }, - - 'down' => function (Builder $schema) { - $schema->table('discussions', function (Blueprint $table) { - $table->dropColumn('views'); - }); - } -]; +return Migration::addColumns("discussions", [ + "views" => ["integer", "default" => 0] +]); \ No newline at end of file diff --git a/migrations/2018_11_30_141817_discussions_rename_views.php b/migrations/2018_11_30_141817_discussions_rename_views.php new file mode 100644 index 0000000..e97b0d9 --- /dev/null +++ b/migrations/2018_11_30_141817_discussions_rename_views.php @@ -0,0 +1,5 @@ +listen(ConfigureWebApp::class, [$this, 'configAssets']); - $events->listen(ConfigureLocales::class, [$this, 'configLocales']); - } - - /** - * @param ConfigureWebApp $event - */ - public function configAssets(ConfigureWebApp $event) - { - if($event->isForum()) - { - $event->addAssets([ - __DIR__.'/../../js/forum/dist/extension.js', - __DIR__.'/../../less/extension.less' - ]); - $event->addBootstrapper('michaelbelgium/flarum-discussion-views/main'); - } - - if($event->isAdmin()) - { - $event->addAssets([ - __DIR__.'/../../js/admin/dist/extension.js' - ]); - $event->addBootstrapper('michaelbelgium/flarum-discussion-views/main'); - } - } - - /** - * @param ConfigureLocales $event - */ - public function configLocales(ConfigureLocales $event) - { - foreach (new DirectoryIterator(__DIR__.'/../../locale') as $file) { - if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'], false)) { - $event->locales->addTranslations($file->getBasename('.'.$file->getExtension()), $file->getPathname()); - } - } - } -} diff --git a/src/listeners/AddDiscussionApiAttributes.php b/src/listeners/AddDiscussionApiAttributes.php index 95f6d8c..430e57e 100644 --- a/src/listeners/AddDiscussionApiAttributes.php +++ b/src/listeners/AddDiscussionApiAttributes.php @@ -3,7 +3,7 @@ namespace michaelbelgium\views\listeners; use Flarum\Api\Serializer\DiscussionSerializer; -use Flarum\Event\PrepareApiAttributes; +use Flarum\Api\Event\Serializing; use Illuminate\Contracts\Events\Dispatcher; class AddDiscussionApiAttributes @@ -13,17 +13,17 @@ class AddDiscussionApiAttributes */ public function subscribe(Dispatcher $events) { - $events->listen(PrepareApiAttributes::class, [$this, 'addApiAttributes']); + $events->listen(Serializing::class, [$this, 'addApiAttributes']); } /** - * @param PrepareApiAttributes $event + * @param Serializing $event */ - public function addApiAttributes(PrepareApiAttributes $event) + public function addApiAttributes(Serializing $event) { if ($event->isSerializer(DiscussionSerializer::class)) { - $event->attributes['views'] = $event->model->views; + $event->attributes['views'] = $event->model->view_count; $event->attributes['canReset'] = (bool)$event->actor->can('resetViews'); } } diff --git a/src/listeners/AddDiscussionViewHandler.php b/src/listeners/AddDiscussionViewHandler.php index 936c06d..da85f2f 100644 --- a/src/listeners/AddDiscussionViewHandler.php +++ b/src/listeners/AddDiscussionViewHandler.php @@ -3,8 +3,8 @@ namespace michaelbelgium\views\listeners; use Flarum\Api\Controller\ShowDiscussionController; -use Flarum\Core\Discussion; -use Flarum\Event\PrepareApiData; +use Flarum\Discussion\Discussion; +use Flarum\Api\Event\WillSerializeData; use Illuminate\Contracts\Events\Dispatcher; use michaelbelgium\views\events\DiscussionWasViewed; @@ -15,19 +15,19 @@ class AddDiscussionViewHandler */ public function subscribe(Dispatcher $events) { - $events->listen(PrepareApiData::class, [$this, "addView"]); + $events->listen(WillSerializeData::class, [$this, "addView"]); } /** - * @param PrepareApiData $event + * @param WillSerializeData $event */ - public function addView(PrepareApiData $event) + public function addView(WillSerializeData $event) { if ($event->isController(ShowDiscussionController::class)) { /** @var Discussion $current_discussion */ $current_discussion = $event->data; - $current_discussion->views++; + $current_discussion->view_count++; event(new DiscussionWasViewed($event->actor, $current_discussion)); $current_discussion->save(); diff --git a/src/listeners/AddPopularSort.php b/src/listeners/AddPopularSort.php index c8289e9..7f8f403 100644 --- a/src/listeners/AddPopularSort.php +++ b/src/listeners/AddPopularSort.php @@ -2,7 +2,7 @@ namespace michaelbelgium\views\listeners; use Illuminate\Contracts\Events\Dispatcher; -use Flarum\Event\ConfigureApiController; +use Flarum\Api\Event\WillGetData; class AddPopularSort { @@ -11,14 +11,14 @@ class AddPopularSort */ public function subscribe(Dispatcher $events) { - $events->listen(ConfigureApiController::class, [$this, 'confApi']); + $events->listen(WillGetData::class, [$this, 'confApi']); } /** - * @param ConfigureApiController $event + * @param WillGetData $event */ - public function confApi(ConfigureApiController $event) + public function confApi(WillGetData $event) { - $event->addSortField('views'); + $event->addSortField('view_count'); } } \ No newline at end of file diff --git a/src/listeners/SaveDiscussionFromModal.php b/src/listeners/SaveDiscussionFromModal.php index 6845cb9..ddb3b16 100644 --- a/src/listeners/SaveDiscussionFromModal.php +++ b/src/listeners/SaveDiscussionFromModal.php @@ -2,22 +2,22 @@ namespace michaelbelgium\views\listeners; use Illuminate\Contracts\Events\Dispatcher; -use Flarum\Event\DiscussionWillBeSaved; +use Flarum\Discussion\Event\Saving; class SaveDiscussionFromModal { public function subscribe(Dispatcher $events) { - $events->listen(DiscussionWillBeSaved::class, [$this, 'OnDiscussionGetSaved']); + $events->listen(Saving::class, [$this, 'OnDiscussionGetSaved']); } - public function OnDiscussionGetSaved(DiscussionWillBeSaved $event) + public function OnDiscussionGetSaved(Saving $event) { if(isset($event->data["attributes"]["views"])) { $discussion = $event->discussion; - $discussion->views = $event->data["attributes"]["views"]; + $discussion->view_count = $event->data["attributes"]["views"]; $discussion->save(); } }