import React, { Component } from 'react' import Notifications from '../../../utils/notifications.js' import {observer, inject} from "mobx-react" import { withTranslation } from 'react-i18next'; import {PageReview, PageReviewChange} from "../../view/collaboration/Review"; import {LocalStorage} from "../../../utils/LocalStorage"; class InitReview extends Component { constructor(props){ super(props); Common.Notifications.on('engineCreated', api => { api.asc_registerCallback('asc_onShowRevisionsChange', this.onChangeReview.bind(this)); }); Common.Notifications.on('document:ready', () => { const api = Common.EditorApi.get(); const appOptions = props.storeAppOptions; let trackChanges = appOptions.customization && appOptions.customization.review ? appOptions.customization.review.trackChanges : undefined; (trackChanges===undefined) && (trackChanges = appOptions.customization ? appOptions.customization.trackChanges : undefined); trackChanges = appOptions.isReviewOnly || trackChanges === true || trackChanges !== false && LocalStorage.getBool("de-mobile-track-changes-" + (appOptions.fileKey || '')); api.asc_SetTrackRevisions(trackChanges); // Init display mode const canViewReview = appOptions.canReview || appOptions.isEdit || api.asc_HaveRevisionsChanges(true); if (!appOptions.canReview) appOptions.setCanViewReview(canViewReview); if (canViewReview) { let viewReviewMode = (appOptions.isEdit || appOptions.isRestrictedEdit) ? null : LocalStorage.getItem("de-view-review-mode"); if (viewReviewMode === null) { viewReviewMode = appOptions.customization && appOptions.customization.review ? appOptions.customization.review.reviewDisplay : undefined; !viewReviewMode && (viewReviewMode = appOptions.customization ? appOptions.customization.reviewDisplay : undefined); viewReviewMode = /^(original|final|markup|simple)$/i.test(viewReviewMode) ? viewReviewMode.toLocaleLowerCase() : ( appOptions.isEdit || appOptions.isRestrictedEdit ? 'markup' : 'original'); } let displayMode = viewReviewMode.toLocaleLowerCase(); let type = Asc.c_oAscDisplayModeInReview.Edit; switch (displayMode) { case 'final': type = Asc.c_oAscDisplayModeInReview.Final; break; case 'original': type = Asc.c_oAscDisplayModeInReview.Original; break; } api.asc_SetDisplayModeInReview(type); props.storeReview.changeDisplayMode(displayMode); } }); } onChangeReview (data) { const storeReview = this.props.storeReview; storeReview.changeArrReview(data); } render() { return null } } class Review extends Component { constructor(props) { super(props); this.onTrackChanges = this.onTrackChanges.bind(this); this.onDisplayMode = this.onDisplayMode.bind(this); this.appConfig = props.storeAppOptions; this.editorPrefix = window.editorType || ''; let trackChanges = this.appConfig.customization && this.appConfig.customization.review ? this.appConfig.customization.review.trackChanges : undefined; (trackChanges===undefined) && (trackChanges = this.appConfig.customization ? this.appConfig.customization.trackChanges : undefined); trackChanges = this.appConfig.isReviewOnly || trackChanges === true || trackChanges !== false && LocalStorage.getBool(`${this.editorPrefix}-mobile-track-changes-${this.appConfig.fileKey || ''}`); this.state = { trackChanges: trackChanges } } onTrackChanges (checked) { const api = Common.EditorApi.get(); if ( this.appConfig.isReviewOnly ) { this.setState({trackChanges: true}); } else { this.setState({trackChanges: checked}); api.asc_SetTrackRevisions(checked); LocalStorage.setBool(`${this.editorPrefix}-mobile-track-changes-${this.appConfig.fileKey || ''}`, checked); } } onAcceptAll () { const api = Common.EditorApi.get(); api.asc_AcceptAllChanges(); } onRejectAll () { const api = Common.EditorApi.get(); api.asc_RejectAllChanges(); } onDisplayMode (mode) { const api = Common.EditorApi.get(); let type = Asc.c_oAscDisplayModeInReview.Edit; switch (mode) { case 'final': type = Asc.c_oAscDisplayModeInReview.Final; break; case 'original': type = Asc.c_oAscDisplayModeInReview.Original; break; } api.asc_SetDisplayModeInReview(type); !this.appConfig.isEdit && !this.appConfig.isRestrictedEdit && LocalStorage.setItem("de-view-review-mode", mode); this.props.storeReview.changeDisplayMode(mode); } render() { const displayMode = this.props.storeReview.displayMode; const isReviewOnly = this.appConfig.isReviewOnly; const canReview = this.appConfig.canReview; const canUseReviewPermissions = this.appConfig.canUseReviewPermissions; const isRestrictedEdit = this.appConfig.isRestrictedEdit; return ( ) } } class ReviewChange extends Component { constructor (props) { super(props); this.onAcceptCurrentChange = this.onAcceptCurrentChange.bind(this); this.onRejectCurrentChange = this.onRejectCurrentChange.bind(this); this.onGotoNextChange = this.onGotoNextChange.bind(this); this.onDeleteChange = this.onDeleteChange.bind(this); this.appConfig = props.storeAppOptions; } dateToLocaleTimeString (date) { const format = (date) => { let strTime, hours = date.getHours(), minutes = date.getMinutes(), ampm = hours >= 12 ? 'pm' : 'am'; hours = hours % 12; hours = hours ? hours : 12; // the hour '0' should be '12' minutes = minutes < 10 ? '0' + minutes : minutes; strTime = hours + ':' + minutes + ' ' + ampm; return strTime; }; // MM/dd/yyyy hh:mm AM return (date.getMonth() + 1) + '/' + (date.getDate()) + '/' + date.getFullYear() + ' ' + format(date); } getArrChangeReview (data) { const api = Common.EditorApi.get(); const { t } = this.props; const _t = t("Common.Collaboration", { returnObjects: true }); if (data.length === 0) return []; const arr = []; const c_paragraphLinerule = { LINERULE_LEAST: 0, LINERULE_AUTO: 1, LINERULE_EXACT: 2 }; data.forEach((item) => { let changeText = [], proptext = [], value = item.get_Value(), movetype = item.get_MoveType(); switch (item.get_Type()) { case Asc.c_oAscRevisionsChangeType.TextAdd: changeText.push(); if (typeof value == 'object') { value.forEach( (obj) => { if (typeof obj === 'string') changeText.push(); else { switch (obj) { case 0: changeText.push(); break; case 1: changeText.push(); break; case 2: changeText.push(); break; case 3: changeText.push(); break; } } }) } else if (typeof value === 'string') { changeText.push(); } break; case Asc.c_oAscRevisionsChangeType.TextRem: changeText.push(); if (typeof value == 'object') { value.forEach( (obj) => { if (typeof obj === 'string') changeText.push(); else { switch (obj) { case 0: changeText.push(); break; case 1: changeText.push(); break; case 2: changeText.push(); break; case 3: changeText.push(); break; } } }) } else if (typeof value === 'string') { changeText.push(); } break; case Asc.c_oAscRevisionsChangeType.ParaAdd: changeText.push(); break; case Asc.c_oAscRevisionsChangeType.ParaRem: changeText.push(); break; case Asc.c_oAscRevisionsChangeType.TextPr: if (value.Get_Bold() !== undefined) proptext.push(); if (value.Get_Italic() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Underline() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Strikeout() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_DStrikeout() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Caps() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_SmallCaps() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_VertAlign() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Color() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Highlight() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Shd() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_FontFamily() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_FontSize() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Spacing() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Position() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Lang() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (proptext.length > 0) { changeText.push(); proptext.forEach((item) => { changeText.push(item); }); } else { changeText.push(); } break; case Asc.c_oAscRevisionsChangeType.ParaPr: if (value.Get_ContextualSpacing()) proptext.push(); if (value.Get_IndLeft() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_IndRight() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_IndFirstLine() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Jc() !== undefined) { switch (value.Get_Jc()) { case 0: proptext.length > 0 && proptext.push(); proptext.push(); break; case 1: proptext.length > 0 && proptext.push(); proptext.push(); break; case 2: proptext.length > 0 && proptext.push(); proptext.push(); break; case 3: proptext.length > 0 && proptext.push(); proptext.push(); break; } } if (value.Get_KeepLines() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_KeepNext()) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_PageBreakBefore()) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_SpacingLineRule() !== undefined && value.Get_SpacingLine() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); proptext.push(); proptext.push(); } if (value.Get_SpacingBeforeAutoSpacing()) { proptext.length > 0 && proptext.push(); proptext.push(); } else if (value.Get_SpacingBefore() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_SpacingAfterAutoSpacing()) { proptext.length > 0 && proptext.push(); proptext.push(); } else if (value.Get_SpacingAfter() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_WidowControl()) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_Tabs() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push(); } if (value.Get_NumPr() !== undefined) { proptext.length > 0 && proptext.push(); proptext.push() } if (value.Get_PStyle() !== undefined) { const style = api.asc_GetStyleNameById(value.Get_PStyle()); if (style.length > 0) { proptext.length > 0 && proptext.push(); proptext.push(); } } if (proptext.length > 0) { changeText.push(); proptext.forEach((item) => { changeText.push(item); }); } else { changeText.push(); } break; case Asc.c_oAscRevisionsChangeType.TablePr: changeText.push(); break; case Asc.c_oAscRevisionsChangeType.RowsAdd: changeText.push(); break; case Asc.c_oAscRevisionsChangeType.RowsRem: changeText.push(); break; } let date = (item.get_DateTime() == '') ? new Date() : new Date(item.get_DateTime()); const user = item.get_UserName(); const userColor = item.get_UserColor(); const goto = (item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveTo || item.get_MoveType() == Asc.c_oAscRevisionsMove.MoveFrom); date = this.dateToLocaleTimeString(date); const editable = this.appConfig.isReviewOnly && (item.get_UserId() == this.appConfig.user.id) || !this.appConfig.isReviewOnly && (!this.appConfig.canUseReviewPermissions || AscCommon.UserInfoParser.canEditReview(item.get_UserName())); arr.push({date: date, user: user, userColor: userColor, changeText: changeText, goto: goto, editable: editable}); }); return arr; } onPrevChange () { const api = Common.EditorApi.get(); api.asc_GetPrevRevisionsChange(); } onNextChange () { const api = Common.EditorApi.get(); api.asc_GetNextRevisionsChange(); } onAcceptCurrentChange () { const api = Common.EditorApi.get(); api.asc_AcceptChanges(this.dataChanges[0]); setTimeout(() => { api.asc_GetNextRevisionsChange(); }); } onRejectCurrentChange () { const api = Common.EditorApi.get(); api.asc_RejectChanges(this.dataChanges[0]); setTimeout(() => { api.asc_GetNextRevisionsChange(); }); } onGotoNextChange () { const api = Common.EditorApi.get(); api.asc_FollowRevisionMove(this.dataChanges[0]); } onDeleteChange () { const api = Common.EditorApi.get(); api.asc_RejectChanges(this.dataChanges[0]); } render() { this.dataChanges = this.props.storeReview.dataChanges; const arrChangeReview = this.getArrChangeReview(this.dataChanges); let change; let goto = false; if (arrChangeReview.length > 0) { const name = AscCommon.UserInfoParser.getParsedName(arrChangeReview[0].user); change = { date: arrChangeReview[0].date, user: arrChangeReview[0].user, userName: Common.Utils.String.htmlEncode(name), color: arrChangeReview[0].userColor.get_hex(), text: arrChangeReview[0].changeText, initials: this.props.users.getInitials(name), editable: arrChangeReview[0].editable }; goto = arrChangeReview[0].goto; } const isReviewOnly = this.appConfig.isReviewOnly; const canReview = this.appConfig.canReview; const displayMode = this.props.storeReview.displayMode; return ( ) } } const InitReviewController = inject("storeAppOptions", "storeReview")(observer(InitReview)); const ReviewController = inject("storeAppOptions", "storeReview")(observer(Review)); const ReviewChangeController = withTranslation()(inject("storeAppOptions", "storeReview", "users")(observer(ReviewChange))); export {InitReviewController, ReviewController, ReviewChangeController};