gitlab-org--gitlab-foss/app/assets/javascripts/sidebar/stores/sidebar_store.js

137 lines
3.3 KiB
JavaScript
Raw Normal View History

export default class SidebarStore {
2017-12-07 17:37:33 +00:00
constructor(options) {
if (!SidebarStore.singleton) {
2017-12-07 17:37:33 +00:00
this.initSingleton(options);
}
return SidebarStore.singleton;
}
2017-12-07 17:37:33 +00:00
initSingleton(options) {
const { currentUser, rootPath, editable, timeTrackingLimitToHours } = options;
2017-12-07 17:37:33 +00:00
this.currentUser = currentUser;
this.rootPath = rootPath;
this.editable = editable;
this.timeEstimate = 0;
this.totalTimeSpent = 0;
this.humanTimeEstimate = '';
this.humanTimeSpent = '';
this.timeTrackingLimitToHours = timeTrackingLimitToHours;
2017-12-07 17:37:33 +00:00
this.assignees = [];
this.reviewers = [];
2017-12-07 17:37:33 +00:00
this.isFetching = {
assignees: true,
reviewers: true,
2017-12-07 17:37:33 +00:00
participants: true,
subscriptions: true,
};
this.isLoading = {};
this.autocompleteProjects = [];
this.moveToProjectId = 0;
this.isLockDialogOpen = false;
this.participants = [];
this.projectEmailsDisabled = false;
this.subscribeDisabledDescription = '';
2017-12-07 17:37:33 +00:00
this.subscribed = null;
SidebarStore.singleton = this;
}
2017-05-05 18:23:31 +00:00
setAssigneeData(data) {
this.isFetching.assignees = false;
if (data.assignees) {
this.assignees = data.assignees;
}
}
setReviewerData(data) {
this.isFetching.reviewers = false;
if (data.reviewers) {
this.reviewers = data.reviewers;
}
}
2017-05-05 18:23:31 +00:00
setTimeTrackingData(data) {
this.timeEstimate = data.time_estimate;
this.totalTimeSpent = data.total_time_spent;
this.humanTimeEstimate = data.human_time_estimate;
this.humanTotalTimeSpent = data.human_total_time_spent;
}
2017-10-31 16:15:03 +00:00
setParticipantsData(data) {
this.isFetching.participants = false;
this.participants = data.participants || [];
}
setSubscriptionsData(data) {
this.projectEmailsDisabled = data.project_emails_disabled || false;
this.subscribeDisabledDescription = data.subscribe_disabled_description;
2017-10-31 16:15:03 +00:00
this.isFetching.subscriptions = false;
this.subscribed = data.subscribed || false;
}
setFetchingState(key, value) {
this.isFetching[key] = value;
}
setLoadingState(key, value) {
this.isLoading[key] = value;
}
addAssignee(assignee) {
if (!this.findAssignee(assignee)) {
this.assignees.push(assignee);
}
}
addReviewer(reviewer) {
if (!this.findReviewer(reviewer)) {
this.reviewers.push(reviewer);
}
}
findAssignee(findAssignee) {
return this.assignees.find(assignee => assignee.id === findAssignee.id);
}
findReviewer(findReviewer) {
return this.reviewers.find(reviewer => reviewer.id === findReviewer.id);
}
removeAssignee(removeAssignee) {
if (removeAssignee) {
this.assignees = this.assignees.filter(assignee => assignee.id !== removeAssignee.id);
}
}
removeReviewer(removeReviewer) {
if (removeReviewer) {
this.reviewers = this.reviewers.filter(reviewer => reviewer.id !== removeReviewer.id);
}
}
removeAllAssignees() {
this.assignees = [];
}
removeAllReviewers() {
this.reviewers = [];
}
setAssigneesFromRealtime(data) {
this.assignees = data;
}
setAutocompleteProjects(projects) {
this.autocompleteProjects = projects;
}
2017-10-31 16:15:03 +00:00
setSubscribedState(subscribed) {
this.subscribed = subscribed;
}
setMoveToProjectId(moveToProjectId) {
this.moveToProjectId = moveToProjectId;
}
}