{"version":3,"sources":["webpack:///../WCC.UI/App/components/ideationVotePicker/ideationVotePicker.html?5122","webpack:///../WCC.UI/App/components/ideationVotePicker/ideationVotePicker.scss?4077","webpack:///../WCC.UI/App/components/ideationVotePicker/ideationVotePicker.ts","webpack:///../WCC.UI/App/managers/ideation.ts","webpack:///../WCC.UI/App/managers/topic/votes.ts","webpack:///../WCC.UI/App/models/threadVote.ts","webpack:///../WCC.UI/App/webpack/runtime/htmlExposer.js","webpack:///../WCC.UI/App/components/ideationVotePicker/ideationVotePicker.scss","webpack:///../WCC.UI/App/components/ideationVotePicker/ideationVotePicker.html"],"names":["content","expose","__esModule","default","api","module","i","options","exports","locals","components","preload","IdeationVotePickerVM","constructor","config","info","storage","effects","pickedVote","ko","observable","pickedUpvote","this","mapNotNull","vote","undefined","pickedDownvote","upvotesShown","downvotesShown","mainControlsShown","pureComputed","showUpvotes","showDownvotes","showMainControls","reset","initialVote","topicManager","get","TopicManager","topicId","loadingTopic","pluck","t","loading","topic","m","upvotesPerIdea","ideationUpvotesMaxPerIdea","downvotesPerIdea","ideationDownvotesMaxPerIdea","votesManager","IdeationManager","votesReady","isReady","availableUpvotes","availableDownvotes","flattenComputed","mapSingle","v","initialUpvotes","initialDownvotes","finalAvailableUpvotes","finalAvailableDownvotes","availableUpvotesPerIdea","Math","min","availableDownvotesPerIdea","upvoteControls","getUpvoteControls","downvoteControls","getDownvoteControls","hasDownvotes","is","register","subscribe","applyBindingsToNode","element","pickVote","value","count","values","Array","map","idx","getVoteControls","__decorate","injectable","__param","inject","wccModules","componentConfig","componentInfo","_ref","user","CurrentUserManager","discussionId","settings","person","isRegularUser","u","isRegular","isIdeation","stage","ideationStage","upvotesCount","ideationUpvotes","downvotesCount","ideationDownvotes","TopicVotesManager","loadingVotes","votes","personUpvotes","filter","personDownvotes","usedUpvotes","reduce","r","usedDownvotes","hasUpvotes","isRatingStage","enums","IdeationStages","IdeaRating","isDoneVoting","isVotingStage","managerConfig","topicsService","source","CollectionDataSource","load","bind","mapper","jsonVote","ThreadVote","list","busy","requestsProcessed","updating","withEffect","events","replyAdded","on","onLocalReplyAdded","replyUpdated","onLocalReplyUpdated","replyDeleted","onLocalReplyDeleted","update","queries","toArray","WCCEntity","json","super","personId","createField","threadId","linkedThreadId","system","SystemHelpers","html","getTemplatesAndResources","forEach","node","document","head","appendChild","___CSS_LOADER_API_IMPORT___","push"],"mappings":"yJAAA,UAAO,CACC,yHACA,wDAIC,KAJyC,EAAF,SAAYA,EAASC,GAGzD,OADAA,EADAD,EAAUA,EAAQE,WAAaF,EAAQG,QAAUH,GAE1CA,GACV,4B,sFCNT,IAAII,EAAM,EAAQ,gFACFJ,EAAU,EAAQ,oKAIC,iBAFvBA,EAAUA,EAAQE,WAAaF,EAAQG,QAAUH,KAG/CA,EAAU,CAAC,CAACK,EAAOC,EAAIN,EAAS,MAG9C,IAAIO,EAAU,CAEd,OAAiB,OACjB,WAAoB,GAEPH,EAAIJ,EAASO,GAI1BF,EAAOG,QAAUR,EAAQS,QAAU,I,k4BCRnCC,EAAWC,QAAQ,eAanB,IAAqBC,EAArB,MAiBIC,YACwCC,EACFC,EACNC,EACAC,GAlBhC,KAAAC,WAA6CC,EAAGC,aAChD,KAAAC,aAAeC,KAAKJ,WAAWK,WAAWC,GAAQA,EAAO,EAAIA,OAAOC,GACpE,KAAAC,eAAiBJ,KAAKJ,WAAWK,WAAWC,GAAQA,EAAO,EAAIA,OAAOC,GAOtE,KAAAE,aAAeR,EAAGC,YAAW,GAC7B,KAAAQ,eAAiBT,EAAGC,YAAW,GAE/B,KAAAS,kBAAoBV,EAAGW,aAAa,KAAOR,KAAKK,iBAAmBL,KAAKM,kBAkDxE,KAAAG,YAAc,KACVT,KAAKK,cAAa,IAGtB,KAAAK,cAAgB,KACZV,KAAKM,gBAAe,IAGxB,KAAAK,iBAAmB,KACfX,KAAKK,cAAa,GAClBL,KAAKM,gBAAe,IAGxB,KAAAM,MAAQ,KACJZ,KAAKW,mBACLX,KAAKJ,WAAW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gBAClBtC,EAAA,EAAAC,YAAOC,IAAWzE,UAClBuE,EAAA,EAAAC,YAAOC,IAAWqC,gBAClBvC,EAAA,EAAAC,YAAOC,IAAWxE,WAbN2F,W,yIChBrB,4EASc,MAAOyB,UAAmBiB,IAMpCzI,YAAY0I,GACRC,QAEAlI,KAAKmI,SAAWnI,KAAKoI,YAAYH,EAAM,YACvCjI,KAAKqI,SAAWrI,KAAKoI,YAAYH,EAAM,YACvCjI,KAAKwD,MAAQxD,KAAKoI,YAAYH,EAAM,YAAa,GACjDjI,KAAKsI,eAAiBtI,KAAKoI,YAAYH,EAAM,qB,+DCtBrD,WAOC,KAPD,aACI,MAAMM,EAAS,EAAQ,mCAAkBC,cAEzC,OAAO,SAAUC,GACbF,EAAOG,yBAAyBD,GAC3BE,SAAQ,SAAUC,GAAQC,SAASC,KAAKC,YAAYH,QAEhE,+B,oLCLD1J,EADkC,EAAQ,wDAChC8J,EAA4B,IAE9BC,KAAK,CAAClK,EAAOC,EAAI,6QAA8Q,KAEvSD,EAAOG,QAAUA,G,oICHjBH,EAAOG,QAFI","file":"197.0c0270c6df37dea17ca4.js","sourcesContent":["define([\n \"!!../../../node_modules/html-loader/dist/cjs.js??ref--26-1!./ideationVotePicker.html\", \n \"!../../webpack/runtime/htmlExposer.js\"], function (content, expose) {\n content = content.__esModule ? content.default : content;\n expose(content);\n return content;\n });","var api = require(\"!../../../node_modules/style-loader/dist/runtime/injectStylesIntoStyleTag.js\");\n var content = require(\"!!../../../node_modules/css-loader/dist/cjs.js!../../../node_modules/sass-loader/dist/cjs.js!./ideationVotePicker.scss\");\n\n content = content.__esModule ? content.default : content;\n\n if (typeof content === 'string') {\n content = [[module.id, content, '']];\n }\n\nvar options = {};\n\noptions.insert = \"head\";\noptions.singleton = false;\n\nvar update = api(content, options);\n\n\n\nmodule.exports = content.locals || {};","import { wccModules } from 'enums/wccModules';\r\nimport { inject, injectable } from 'inversify';\r\nimport { Observable, Subscribable, SubscribableOrNullableValue } from 'knockout';\r\nimport IdeationManager from 'managers/ideation';\r\nimport { IWCCStorageManager } from 'managers/iStorage';\r\nimport { TopicManager } from 'managers/topic';\r\nimport { EffectsContainer } from 'mixins/withEffects';\r\nimport './ideationVotePicker.html';\r\nimport './ideationVotePicker.scss';\r\n\r\ncomponents.preload('vote-bubble');\r\n\r\ninterface VoteControl {\r\n value: number\r\n pickVote: Action\r\n}\r\n\r\nexport interface IdeationVotePickerVMConfig {\r\n topicId?: SubscribableOrNullableValue\r\n initialVote?: SubscribableOrNullableValue\r\n}\r\n\r\n@injectable()\r\nexport default class IdeationVotePickerVM {\r\n private initialVote: Subscribable\r\n\r\n pickedVote: Observable = ko.observable();\r\n pickedUpvote = this.pickedVote.mapNotNull(vote => vote > 0 ? vote : undefined);\r\n pickedDownvote = this.pickedVote.mapNotNull(vote => vote < 0 ? vote : undefined);\r\n\r\n upvoteControls: Subscribable>\r\n downvoteControls: Subscribable>\r\n\r\n hasDownvotes: Subscribable\r\n\r\n upvotesShown = ko.observable(false);\r\n downvotesShown = ko.observable(false);\r\n\r\n mainControlsShown = ko.pureComputed(() => !this.upvotesShown() && !this.downvotesShown());\r\n\r\n constructor(\r\n @inject(wccModules.componentConfig) config: IdeationVotePickerVMConfig,\r\n @inject(wccModules.componentInfo) info: ko.components.ComponentInfo,\r\n @inject(wccModules.storage) storage: IWCCStorageManager,\r\n @inject(wccModules.effects) effects: EffectsContainer\r\n ) {\r\n const topicManager = storage.get(TopicManager, { topicId: config.topicId });\r\n const loadingTopic = topicManager.pluck(t => t.loading, true);\r\n const topic = topicManager.pluck(m => m.topic);\r\n const upvotesPerIdea = topic.pluck(t => t.ideationUpvotesMaxPerIdea, 0);\r\n const downvotesPerIdea = topic.pluck(t => t.ideationDownvotesMaxPerIdea, 0);\r\n\r\n const votesManager = storage.get(IdeationManager, { topicId: config.topicId });\r\n const votesReady = votesManager.pluck(m => m.isReady, false);\r\n const availableUpvotes = votesManager.pluck(m => m.availableUpvotes, 0);\r\n const availableDownvotes = votesManager.pluck(m => m.availableDownvotes, 0);\r\n\r\n const initialVote = ko.flattenComputed(config.initialVote, 0);\r\n this.initialVote = initialVote.mapSingle(v => v != 0 ? v : undefined);//we replace 0 with undefined to allow value picking\r\n const initialUpvotes = this.initialVote.mapSingle(v => v != undefined && v > 0 ? v : 0);\r\n const initialDownvotes = this.initialVote.mapSingle(v => v != undefined && v < 0 ? -v : 0);\r\n\r\n const finalAvailableUpvotes = ko.pureComputed(() => availableUpvotes() + initialUpvotes());\r\n const finalAvailableDownvotes = ko.pureComputed(() => availableDownvotes() + initialDownvotes());\r\n\r\n const availableUpvotesPerIdea = ko.pureComputed(() => Math.min(upvotesPerIdea(), finalAvailableUpvotes()));\r\n const availableDownvotesPerIdea = ko.pureComputed(() => Math.min(downvotesPerIdea(), finalAvailableDownvotes()));\r\n\r\n this.upvoteControls = ko.pureComputed(() => this.getUpvoteControls(availableUpvotesPerIdea()));\r\n this.downvoteControls = ko.pureComputed(() => this.getDownvoteControls(availableDownvotesPerIdea()));\r\n\r\n this.hasDownvotes = availableDownvotesPerIdea.is(v => v > 0);\r\n\r\n const isReady = ko.pureComputed(() => !loadingTopic() && votesReady());\r\n\r\n effects.register([\r\n this.initialVote.subscribe(() => this.reset())\r\n ]);\r\n\r\n ko.applyBindingsToNode(info.element, {\r\n 'visible': isReady,\r\n\r\n 'css': {\r\n 'ideation-vote-picker': true\r\n }\r\n });\r\n }\r\n\r\n showUpvotes = () => {\r\n this.upvotesShown(true);\r\n }\r\n\r\n showDownvotes = () => {\r\n this.downvotesShown(true);\r\n }\r\n\r\n showMainControls = () => {\r\n this.upvotesShown(false);\r\n this.downvotesShown(false);\r\n }\r\n\r\n reset = () => {\r\n this.showMainControls();\r\n this.pickedVote(this.initialVote());\r\n }\r\n\r\n private pickVote(value: number) {\r\n this.pickedVote(value);\r\n this.showMainControls();\r\n }\r\n\r\n private getUpvoteControls(count: number) {\r\n const values = [...Array(count)].map((v, idx) => idx + 1);\r\n return this.getVoteControls(values);\r\n }\r\n\r\n private getDownvoteControls(count: number) {\r\n const values = [...Array(count)].map((v, idx) => -(idx + 1));\r\n return this.getVoteControls(values);\r\n }\r\n\r\n private getVoteControls(values: Array) {\r\n return values.map(value => ({\r\n value: value,\r\n pickVote: () => this.pickVote(value)\r\n }));\r\n }\r\n}","import { wccModules } from 'enums/wccModules';\r\nimport { inject, injectable } from 'inversify';\r\nimport { PureComputed, Subscribable } from 'knockout';\r\nimport { CurrentUserManager } from 'managers/currentUser';\r\nimport { IWCCStorageManager } from 'managers/iStorage';\r\nimport { TopicManager } from 'managers/topic';\r\nimport TopicVotesManager from './topic/votes';\r\n\r\nexport interface TopicVotesManagerConfig {\r\n topicId: string\r\n}\r\n\r\n@injectable()\r\nexport default class IdeationManager {\r\n stage: Subscribable\r\n\r\n availableUpvotes: Subscribable\r\n availableDownvotes: Subscribable\r\n\r\n hasUpvotes: Subscribable\r\n hasDownvotes: Subscribable\r\n\r\n isIdeation: Subscribable\r\n isRatingStage: Subscribable\r\n isVotingStage: Subscribable\r\n isDoneVoting: Subscribable\r\n\r\n isReady: Subscribable\r\n\r\n constructor(\r\n @inject(wccModules.managerConfig) { topicId }: TopicVotesManagerConfig,\r\n @inject(wccModules.storage) storage: IWCCStorageManager\r\n ) {\r\n const userManager = storage.get(CurrentUserManager, { discussionId: settings.discussionId });\r\n const user = userManager.pluck(m => m.person);\r\n const isRegularUser = user.pluck(u => u.isRegular, false);\r\n\r\n const topicManager = storage.get(TopicManager, { topicId });\r\n const topic = topicManager.pluck(m => m.topic);\r\n this.isIdeation = topic.pluck(t => t.isIdeation, false);\r\n this.stage = topic.pluck(t => t.ideationStage, 0);\r\n const upvotesCount = topic.pluck(t => t.ideationUpvotes, 0);\r\n const downvotesCount = topic.pluck(t => t.ideationDownvotes, 0);\r\n\r\n const votesManager = storage.get(TopicVotesManager, { topicId: topicId });\r\n const loadingVotes = votesManager.pluck(m => m.loading, true);\r\n const votes = votesManager.pluck(m => m.votes, []);\r\n\r\n const personUpvotes = votes.filter(v => v.value() > 0);\r\n const personDownvotes = votes.filter(v => v.value() < 0);\r\n\r\n const usedUpvotes = personUpvotes.reduce((r, v) => r + v.value(), () => 0);\r\n this.availableUpvotes = ko.pureComputed(() => isRegularUser() ? upvotesCount() - usedUpvotes() : 0);\r\n\r\n const usedDownvotes = personDownvotes.reduce((r, v) => r - v.value(), () => 0);\r\n this.availableDownvotes = ko.pureComputed(() => isRegularUser() ? downvotesCount() - usedDownvotes() : 0);\r\n\r\n this.hasUpvotes = this.availableUpvotes.is(count => count > 0);\r\n this.hasDownvotes = this.availableDownvotes.is(count => count > 0);\r\n\r\n this.isRatingStage = ko.pureComputed(() => this.stage() === enums.IdeationStages.IdeaRating.value);\r\n this.isDoneVoting = this.availableUpvotes.is(0);\r\n\r\n this.isVotingStage = ko.pureComputed(() => this.isIdeation() && isRegularUser() && this.isRatingStage() && !this.isDoneVoting());\r\n\r\n this.isReady = ko.pureComputed(() => !this.isIdeation() || user() != undefined && topic() != undefined && !loadingVotes());\r\n } \r\n}","import { wccModules } from 'enums/wccModules';\r\nimport { inject, injectable } from 'inversify';\r\nimport { PureComputed, Subscribable } from 'knockout';\r\nimport { CollectionDataSource } from 'managers/datasources/collection';\r\nimport events from 'managers/events';\r\nimport IdeationManager from 'managers/ideation';\r\nimport { IWCCStorageManager } from 'managers/iStorage';\r\nimport { withEffect } from 'mixins/withEffect';\r\nimport { EffectsContainer } from 'mixins/withEffects';\r\nimport ThreadVote, { JSONThreadVote } from 'models/threadVote';\r\nimport { TopicsService } from 'services/topics';\r\n\r\nexport interface TopicVotesManagerConfig {\r\n topicId: string\r\n}\r\n\r\n@injectable()\r\nexport default class TopicVotesManager {\r\n private topicId: string\r\n private source: CollectionDataSource\r\n\r\n votes: Subscribable>\r\n\r\n loading: PureComputed\r\n updating: PureComputed\r\n\r\n constructor(\r\n @inject(wccModules.managerConfig) { topicId }: TopicVotesManagerConfig,\r\n @inject(wccModules.storage) storage: IWCCStorageManager,\r\n @inject(wccModules.topicsService) private topicsService: TopicsService,\r\n @inject(wccModules.effects) effects: EffectsContainer,\r\n ) {\r\n this.topicId = topicId;\r\n\r\n this.source = effects.register(new CollectionDataSource({\r\n load: this.load.bind(this),\r\n mapper: jsonVote => new ThreadVote(jsonVote)\r\n }));\r\n\r\n this.votes = this.source.list; \r\n\r\n this.loading = ko.pureComputed(() => this.source.busy() && this.source.requestsProcessed() === 0);\r\n this.updating = ko.pureComputed(() => this.source.busy() && this.source.requestsProcessed() > 0);\r\n\r\n const ideationManager = storage.get(IdeationManager, { topicId: topicId });\r\n const isVotingStage = ideationManager.pluck(m => m.isVotingStage, false);\r\n\r\n //we're inside voting stage so any replies changes require votes update\r\n effects.register(isVotingStage => {\r\n if (isVotingStage) {\r\n return withEffect([\r\n events.replyAdded.on(this.onLocalReplyAdded.bind(this)),\r\n events.replyUpdated.on(this.onLocalReplyUpdated.bind(this)),\r\n events.replyDeleted.on(this.onLocalReplyDeleted.bind(this))\r\n ]);\r\n }\r\n }, [isVotingStage]);\r\n }\r\n\r\n update() {\r\n this.source.load();\r\n }\r\n\r\n private load() {\r\n return this.topicsService.queries.votes(this.topicId).toArray();\r\n }\r\n\r\n private onLocalReplyAdded(topicId: string) {\r\n if (this.topicId == topicId)\r\n this.update();\r\n }\r\n\r\n private onLocalReplyUpdated(topicId: string) {\r\n if (this.topicId == topicId)\r\n this.update();\r\n }\r\n\r\n private onLocalReplyDeleted(topicId: string) {\r\n if (this.topicId == topicId)\r\n this.update();\r\n }\r\n}","import { Observable } from 'knockout';\r\nimport WCCEntity from './entity';\r\n\r\nexport interface JSONThreadVote {\r\n PersonId: string,\r\n ThreadId: string,\r\n VoteValue: number,\r\n LinkedThreadId: string\r\n}\r\n\r\nexport default class ThreadVote extends WCCEntity {\r\n personId: Observable\r\n threadId: Observable\r\n value: Observable\r\n linkedThreadId: Observable\r\n\r\n constructor(json: JSONThreadVote) {\r\n super();\r\n\r\n this.personId = this.createField(json, 'PersonId');\r\n this.threadId = this.createField(json, 'ThreadId');\r\n this.value = this.createField(json, 'VoteValue', 0);\r\n this.linkedThreadId = this.createField(json, 'LinkedThreadId');\r\n }\r\n}","define(function () {\r\n const system = require('helpers/system').SystemHelpers;\r\n\r\n return function (html) {\r\n system.getTemplatesAndResources(html)\r\n .forEach(function (node) { document.head.appendChild(node) });\r\n }\r\n});","// Imports\nvar ___CSS_LOADER_API_IMPORT___ = require(\"../../../node_modules/css-loader/dist/runtime/api.js\");\nexports = ___CSS_LOADER_API_IMPORT___(false);\n// Module\nexports.push([module.id, \".ideation-vote-picker{display:block;padding:10px 10px 5px}.ideation-vote-picker__section{display:flex;flex-wrap:wrap}.ideation-vote-picker__section .vote-bubble{margin-right:5px;margin-bottom:5px}.ideation-vote-picker__section .vote-bubble:last-child{margin-right:0}\", \"\"]);\n// Exports\nmodule.exports = exports;\n","// Module\nvar code = \"\";\n// Exports\nmodule.exports = code;"],"sourceRoot":""}