/
var
/
www
/
html
/
lgpd
/
message
/
amd
/
build
/
Upload File
HOME
{"version":3,"sources":["../src/message_drawer_view_overview.js"],"names":["define","$","KeyCodes","PubSub","Str","Router","Routes","MessageDrawerEvents","Section","MessageRepository","Constants","SELECTORS","CONTACT_REQUEST_COUNT","FAVOURITES","GROUP_MESSAGES","MESSAGES","SEARCH_INPUT","SECTION_TOGGLE_BUTTON","OVERVIEW_SECTION_TYPES","PRIVATE","CONVERSATION_TYPES","SELF","PUBLIC","FAVOURITE","loadAllCountsPromise","loadAllCounts","loggedInUserId","getAllConversationCounts","filterCountsByTypes","counts","types","includeFavourites","total","length","reduce","carry","type","favourites","openSection","sections","isAlreadyOpen","some","section","sectionRoot","isVisible","sort","a","b","aTotal","aUnread","bTotal","bUnread","button","find","click","getSearchInput","header","getLoggedInUserId","body","attr","decrementContactRequestCount","countContainer","count","parseInt","text","isNaN","addClass","registerEventListeners","namespace","searchInput","ignoredKeys","tab","shift","ctrl","alt","on","go","VIEW_SEARCH","e","indexOf","keyCode","key","subscribe","CONTACT_REQUEST_ACCEPTED","CONTACT_REQUEST_DECLINED","show","fromPanel","val","allCounts","forEach","args","sectionTypes","totalCountPromise","then","result","unreadCountPromise","unread","sectionParams","map","totalCount","unreadCount","description","get_string"],"mappings":"AAsBAA,OAAM,6CACN,CACI,QADJ,CAEI,gBAFJ,CAGI,aAHJ,CAII,UAJJ,CAKI,oCALJ,CAMI,oCANJ,CAOI,oCAPJ,CAQI,mDARJ,CASI,iCATJ,CAUI,yDAVJ,CADM,CAaN,SACIC,CADJ,CAEIC,CAFJ,CAGIC,CAHJ,CAIIC,CAJJ,CAKIC,CALJ,CAMIC,CANJ,CAOIC,CAPJ,CAQIC,CARJ,CASIC,CATJ,CAUIC,CAVJ,CAWE,IAEMC,CAAAA,CAAS,CAAG,CACZC,qBAAqB,CAAE,yCADX,CAEZC,UAAU,CAAE,4CAFA,CAGZC,cAAc,CAAE,gDAHJ,CAIZC,QAAQ,CAAE,0CAJE,C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AAT,CAAiB,CACrD,MAAOlE,CAAAA,CAAmB,CAACkE,CAAM,CAACE,MAAR,CAAgBL,CAAhB,CAA8B5D,CAA9B,CAC7B,CAFwB,CAPG,CAW5BvB,CAAO,CAAC6E,IAAR,CAAajB,CAAb,CAAwB,IAAxB,CAA8BzB,CAA9B,CAA2C,IAA3C,CAAiDgD,CAAjD,CAA+D5D,CAA/D,CACI6D,CADJ,CACuBG,CADvB,CAC2CT,CAD3C,CAEH,CAbD,EAeA,MAAOE,CAAAA,CAAS,CAACK,IAAV,CAAe,SAASC,CAAT,CAAiB,CAC/B,GAAIG,CAAAA,CAAa,CAAG1D,CAAQ,CAAC2D,GAAT,CAAa,SAASxD,CAAT,CAAkB,IAC3CC,CAAAA,CAAW,CAAGD,CAAO,CAAC,CAAD,CADsB,CAE3CiD,CAAY,CAAGjD,CAAO,CAAC,CAAD,CAFqB,CAG3CX,CAAiB,CAAGW,CAAO,CAAC,CAAD,CAHgB,CAI3CyD,CAAU,CAAGvE,CAAmB,CAACkE,CAAM,CAAC9D,KAAR,CAAe2D,CAAf,CAA6B5D,CAA7B,CAJW,CAK3CqE,CAAW,CAAGxE,CAAmB,CAACkE,CAAM,CAACE,MAAR,CAAgBL,CAAhB,CAA8B5D,CAA9B,CALU,CAO/C,MAAO,CAACY,CAAD,CAAcwD,CAAd,CAA0BC,CAA1B,CACV,CARmB,CAApB,CAWA,MAAO9D,CAAAA,CAAW,CAAC2D,CAAD,CACrB,CAbE,CAcV,CAWM,CAEHI,WAAW,CANG,QAAdA,CAAAA,WAAc,EAAW,CACzB,MAAOjG,CAAAA,CAAG,CAACkG,UAAJ,CAAe,2BAAf,CAA4C,cAA5C,CACV,CAEM,CAIV,CAnRK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Controls the overview page of the message drawer.\n *\n * @module core_message/message_drawer_view_overview\n * @copyright 2018 Ryan Wyllie <ryan@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(\n[\n 'jquery',\n 'core/key_codes',\n 'core/pubsub',\n 'core/str',\n 'core_message/message_drawer_router',\n 'core_message/message_drawer_routes',\n 'core_message/message_drawer_events',\n 'core_message/message_drawer_view_overview_section',\n 'core_message/message_repository',\n 'core_message/message_drawer_view_conversation_constants'\n],\nfunction(\n $,\n KeyCodes,\n PubSub,\n Str,\n Router,\n Routes,\n MessageDrawerEvents,\n Section,\n MessageRepository,\n Constants\n) {\n\n var SELECTORS = {\n CONTACT_REQUEST_COUNT: '[data-region=\"contact-request-count\"]',\n FAVOURITES: '[data-region=\"view-overview-favourites\"]',\n GROUP_MESSAGES: '[data-region=\"view-overview-group-messages\"]',\n MESSAGES: '[data-region=\"view-overview-messages\"]',\n SEARCH_INPUT: '[data-region=\"view-overview-search-input\"]',\n SECTION_TOGGLE_BUTTON: '[data-toggle]'\n };\n\n // Categories displayed in the message drawer. Some methods (such as filterCountsByType) are expecting their value\n // will be the same as the defined in the CONVERSATION_TYPES, except for the favourite.\n var OVERVIEW_SECTION_TYPES = {\n PRIVATE: [Constants.CONVERSATION_TYPES.PRIVATE, Constants.CONVERSATION_TYPES.SELF],\n PUBLIC: [Constants.CONVERSATION_TYPES.PUBLIC],\n FAVOURITE: null\n };\n\n var loadAllCountsPromise = null;\n\n /**\n * Load the total and unread conversation counts from the server for this user. This function\n * returns a jQuery promise that will be resolved with the counts.\n *\n * The request is only sent once per page load and will be cached for subsequent\n * calls to this function.\n *\n * @param {Number} loggedInUserId The logged in user's id\n * @return {Object} jQuery promise\n */\n var loadAllCounts = function(loggedInUserId) {\n if (loadAllCountsPromise === null) {\n loadAllCountsPromise = MessageRepository.getAllConversationCounts(loggedInUserId);\n }\n\n return loadAllCountsPromise;\n };\n\n /**\n * Filter a set of counts to return only the count for the given type.\n *\n * This is used on the result returned by the loadAllCounts function.\n *\n * @param {Object} counts Conversation counts indexed by conversation type.\n * @param {Array|null} types The conversation types handlded by this section (null for all conversation types).\n * @param {bool} includeFavourites If this section includes favourites\n * @return {Number}\n */\n var filterCountsByTypes = function(counts, types, includeFavourites) {\n var total = 0;\n\n if (types && types.length) {\n total = types.reduce(function(carry, type) {\n return carry + counts.types[type];\n }, total);\n }\n\n if (includeFavourites) {\n total += counts.favourites;\n }\n\n return total;\n };\n\n /**\n * Opens one of the sections based on whether the section has unread conversations\n * or any conversations\n *\n * Default section priority is favourites, groups, then messages. A section can increase\n * in priority if it has conversations in it. It can increase even further if it has\n * unread conversations.\n *\n * @param {Array} sections List of section roots, total counts, and unread counts.\n */\n var openSection = function(sections) {\n var isAlreadyOpen = sections.some(function(section) {\n var sectionRoot = section[0];\n return Section.isVisible(sectionRoot);\n });\n\n if (isAlreadyOpen) {\n // The user has already opened a section so there is nothing to do.\n return;\n }\n\n // Order the sections so that sections with unread conversations are prioritised\n // over sections without and sections with total conversations are prioritised\n // over sections without.\n sections.sort(function(a, b) {\n var aTotal = a[1];\n var aUnread = a[2];\n var bTotal = b[1];\n var bUnread = b[2];\n\n if (aUnread > 0 && bUnread == 0) {\n return -1;\n } else if (aUnread == 0 && bUnread > 0) {\n return 1;\n } else if (aTotal > 0 && bTotal == 0) {\n return -1;\n } else if (aTotal == 0 && bTotal > 0) {\n return 1;\n } else {\n return 0;\n }\n });\n\n // Get the root of the first section after sorting.\n var sectionRoot = sections[0][0];\n var button = sectionRoot.find(SELECTORS.SECTION_TOGGLE_BUTTON);\n // Click it to expand it.\n button.click();\n };\n\n /**\n * Get the search input text element.\n *\n * @param {Object} header Overview header container element.\n * @return {Object} The search input element.\n */\n var getSearchInput = function(header) {\n return header.find(SELECTORS.SEARCH_INPUT);\n };\n\n /**\n * Get the logged in user id.\n *\n * @param {Object} body Overview body container element.\n * @return {String} Logged in user id.\n */\n var getLoggedInUserId = function(body) {\n return body.attr('data-user-id');\n };\n\n /**\n * Decrement the contact request count. If the count is zero or below then\n * hide the count.\n *\n * @param {Object} header Conversation header container element.\n * @return {Function} A function to handle decrementing the count.\n */\n var decrementContactRequestCount = function(header) {\n return function() {\n var countContainer = header.find(SELECTORS.CONTACT_REQUEST_COUNT);\n var count = parseInt(countContainer.text(), 10);\n count = isNaN(count) ? 0 : count - 1;\n\n if (count <= 0) {\n countContainer.addClass('hidden');\n } else {\n countContainer.text(count);\n }\n };\n };\n\n /**\n * Listen to, and handle event in the overview header.\n *\n * @param {String} namespace Unique identifier for the Routes\n * @param {Object} header Conversation header container element.\n */\n var registerEventListeners = function(namespace, header) {\n var searchInput = getSearchInput(header);\n var ignoredKeys = [KeyCodes.tab, KeyCodes.shift, KeyCodes.ctrl, KeyCodes.alt];\n\n searchInput.on('click', function() {\n Router.go(namespace, Routes.VIEW_SEARCH);\n });\n searchInput.on('keydown', function(e) {\n if (ignoredKeys.indexOf(e.keyCode) < 0 && e.key != 'Meta') {\n Router.go(namespace, Routes.VIEW_SEARCH);\n }\n });\n\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_ACCEPTED, decrementContactRequestCount(header));\n PubSub.subscribe(MessageDrawerEvents.CONTACT_REQUEST_DECLINED, decrementContactRequestCount(header));\n };\n\n /**\n * Setup the overview page.\n *\n * @param {String} namespace Unique identifier for the Routes\n * @param {Object} header Overview header container element.\n * @param {Object} body Overview body container element.\n * @return {Object} jQuery promise\n */\n var show = function(namespace, header, body) {\n if (!header.attr('data-init')) {\n registerEventListeners(namespace, header);\n header.attr('data-init', true);\n }\n var fromPanel = header.attr('data-in-panel') ? 'frompanel' : null;\n\n getSearchInput(header).val('');\n var loggedInUserId = getLoggedInUserId(body);\n var allCounts = loadAllCounts(loggedInUserId);\n\n var sections = [\n // Favourite conversations section.\n [body.find(SELECTORS.FAVOURITES), OVERVIEW_SECTION_TYPES.FAVOURITE, true],\n // Group conversations section.\n [body.find(SELECTORS.GROUP_MESSAGES), OVERVIEW_SECTION_TYPES.PUBLIC, false],\n // Private conversations section.\n [body.find(SELECTORS.MESSAGES), OVERVIEW_SECTION_TYPES.PRIVATE, false]\n ];\n\n sections.forEach(function(args) {\n var sectionRoot = args[0];\n var sectionTypes = args[1];\n var includeFavourites = args[2];\n var totalCountPromise = allCounts.then(function(result) {\n return filterCountsByTypes(result.total, sectionTypes, includeFavourites);\n });\n var unreadCountPromise = allCounts.then(function(result) {\n return filterCountsByTypes(result.unread, sectionTypes, includeFavourites);\n });\n\n Section.show(namespace, null, sectionRoot, null, sectionTypes, includeFavourites,\n totalCountPromise, unreadCountPromise, fromPanel);\n });\n\n return allCounts.then(function(result) {\n var sectionParams = sections.map(function(section) {\n var sectionRoot = section[0];\n var sectionTypes = section[1];\n var includeFavourites = section[2];\n var totalCount = filterCountsByTypes(result.total, sectionTypes, includeFavourites);\n var unreadCount = filterCountsByTypes(result.unread, sectionTypes, includeFavourites);\n\n return [sectionRoot, totalCount, unreadCount];\n });\n\n // Open up one of the sections for the user.\n return openSection(sectionParams);\n });\n };\n\n /**\n * String describing this page used for aria-labels.\n *\n * @return {Object} jQuery promise\n */\n var description = function() {\n return Str.get_string('messagedrawerviewoverview', 'core_message');\n };\n\n return {\n show: show,\n description: description\n };\n});\n"],"file":"message_drawer_view_overview.min.js"}