1{"version":3,"sources":["pages/file-history-old/history-item.js","file-history-old.js"],"names":["moment","locale","window","app","config","lang","HistoryItem","props","onMouseEnter","setState","active","onMouseLeave","onItemRestore","e","preventDefault","item","state","this","downloadUrl","URLDecorator","getUrl","type","filePath","objID","rev_file_id","userProfileURL","siteRoot","encodeURIComponent","creator_email","viewUrl","historyRepoID","commit_id","diffUrl","className","datetime","time","is","title","ctime","format","fromNow","index","gettext","src","creator_avatar_url","alt","href","target","creator_name","Utils","bytesToSize","size","canDownload","canCompare","React","Component","MoreMenu","dropdownToggle","dropdownOpen","isOpen","toggle","direction","tag","data-toggle","aria-expanded","right","onClick","PureComponent","FileHistory","listNewHistoryRecords","PER_PAGE","editUtilities","listFileHistoryRecords","then","res","data","isLoading","Error","initNewRecords","listOldHistoryRecords","repoID","seafileAPI","listOldFileHistoryRecords","initOldRecords","onScrollHandler","event","clientHeight","scrollHeight","isBottom","scrollTop","hasMore","reloadMore","isReloadingData","useNewAPI","currentPage","updateNewRecords","commitID","nextCommit","oldFilePath","updateOldRecords","commitId","path","revertFile","success","refershFileList","onSearchedClick","searchedItem","handleSearchedItemClick","historyList","undefined","result","total_count","length","oldPath","old_path","concat","slice","page","next_start_commit","rev_renamed_old_path","id","showCloseSidePanelIcon","onScroll","fileName","width","map","ReactDOM","render","document","getElementById"],"mappings":"8WAQAA,IAAOC,OAAOC,OAAOC,IAAIC,OAAOC,M,IAU1BC,E,kDAEJ,WAAYC,GAAQ,IAAD,8BACjB,cAAMA,IAMRC,aAAe,WACb,EAAKC,SAAS,CACZC,QAAQ,KATO,EAanBC,aAAe,WACb,EAAKF,SAAS,CACZC,QAAQ,KAfO,EAmBnBE,cAAgB,SAACC,GACfA,EAAEC,iBACF,EAAKP,MAAMK,cAAc,EAAKL,MAAMQ,OAnBpC,EAAKC,MAAQ,CACXN,QAAQ,GAHO,E,0CAwBnB,WACE,IAAIK,EAAOE,KAAKV,MAAMQ,KAClBG,EAAcC,IAAaC,OAAO,CAACC,KAAM,yB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iBxF,KAAKwF,uBAGzC,qBAAKe,GAAG,OAAOE,SAAUzG,KAAKmE,gBAA9B,SACE,sBAAKnD,UAAU,mBAAf,UACE,eAAC,WAAD,WACE,mBAAGa,KAAK,mCAAmCb,UAAU,UAAUI,MAAM,OAArE,SACE,sBAAMJ,UAAU,0BAElB,+BAAI,sBAAMA,UAAU,YAAhB,SAA6B0F,OAAiB,IAAKjF,aAAQ,0BAEjE,eAAC,WAAD,WACE,wBAAOT,UAAU,cAAjB,UACE,gCACE,+BACE,oBAAI2F,MAAM,MAAV,SAAkBlF,aAAQ,UAC1B,oBAAIkF,MAAM,MAAV,SAAkBlF,aAAQ,cAC1B,oBAAIkF,MAAM,MAAV,SAAkBlF,aAAQ,UAC1B,oBAAIkF,MAAM,aAGZ3G,KAAKD,MAAM4D,WACX,gCACG3D,KAAKD,MAAM4F,YAAYiB,KAAI,SAAC9G,EAAM0B,GACjC,OACE,cAAC,EAAD,CAEE1B,KAAMA,EACN0B,MAAOA,EACPW,YAAaA,IACbC,WAAYA,IACZzC,cAAe,EAAKA,eALf6B,YAYfxB,KAAKD,MAAM4E,iBAAmB3E,KAAKD,MAAM4D,YAAc,cAAC,IAAD,IACxD3D,KAAKD,MAAMiF,aAAehF,KAAKD,MAAM4D,YAAc3D,KAAKD,MAAM4E,iBAC7D,cAAC,IAAD,CAAQ3D,UAAU,eAAeiC,QAASjD,KAAK0E,WAA/C,SAA4DjD,aAAQ,yB,GAzP1DY,IAAMC,YAmQhCuE,IAASC,OACP,cAAC,EAAD,IACAC,SAASC,eAAe,c","file":"static/js/fileHistoryOld.chunk.js","sourcesContent":["import React, { Fragment } from 'react';\nimport PropTypes from 'prop-types';\nimport moment from 'moment';\nimport { Utils } from '../../utils/utils';\nimport { gettext, siteRoot, filePath, historyRepoID } from '../../utils/constants';\nimport URLDecorator from '../../utils/url-decorator';\nimport { Dropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap';\n\nmoment.locale(window.app.config.lang);\n\nconst propTypes = {\n  item: PropTypes.object.isRequired,\n  index: PropTypes.number.isRequired,\n  canDownload: PropTypes.bool.isRequired,\n  canCompare: PropTypes.bool.isRequired,\n  onItemRestore: PropTypes.func.isRequired,\n};\n\nclass HistoryItem extends React.Component {\n\n  constructor(props) {\n    super(props);\n    this.state = {\n      active: false,\n    };\n  }\n\n  onMouseEnter = () => {\n    this.setState({\n      active: true\n    });\n  }\n\n  onMouseLeave = () => {\n    this.setState({\n      active: false\n    });\n  }\n\n  onItemRestore = (e) => {\n    e.preventDefault();\n    this.props.onItemRestore(this.props.item);\n  }\n\n  render() {\n    let item = this.props.item;\n    let downloadUrl = URLDecorator.getUrl({type: 'download_historic_file', filePath: filePath, objID: item.rev_file_id});\n    let userProfileURL = `${siteRoot}profile/${encodeURIComponent(item.creator_email)}/`;\n    let viewUrl = `${siteRoot}repo/${historyRepoID}/history/files/?obj_id=${item.rev_file_id}&commit_id=${item.commit_id}&p=${filePath}`;\n    let diffUrl = `${siteRoot}repo/text_diff/${historyRepoID}/?commit=${item.commit_id}&p=${filePath}`;\n    return (\n      <Fragment>\n        <tr onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} className={this.state.active ? 'tr-highlight' : ''}>\n          <td>\n            <time datetime={item.time} is=\"relative-time\" title={moment(item.ctime).format('llll')}>{moment(item.ctime).fromNow()}</time>\n            {this.props.index === 0 && gettext('(current version)')}\n          </td>\n          <td>\n            <img className=\"avatar\" src={item.creator_avatar_url} alt=''></img>{' '}\n            <a href={userProfileURL} target='_blank' className=\"username\">{item.creator_name}</a>\n          </td>\n          <td>{Utils.bytesToSize(item.size)}</td>\n          <td>\n            {this.state.active &&\n              <MoreMenu\n                index={this.props.index}\n                downloadUrl={downloadUrl}\n                viewUrl={viewUrl}\n                diffUrl={diffUrl}\n                onItemRestore={this.onItemRestore}\n                canDownload={this.props.canDownload}\n                canCompare={this.props.canCompare}\n              />\n            }\n          </td>\n        </tr>\n      </Fragment>\n    );\n  }\n}\n\nHistoryItem.propTypes = propTypes;\n\n\nconst MoreMenuPropTypes = {\n  index: PropTypes.number.isRequired,\n  downloadUrl: PropTypes.string.isRequired,\n  viewUrl: PropTypes.string.isRequired,\n  diffUrl: PropTypes.string.isRequired,\n  onItemRestore: PropTypes.func.isRequired,\n  canDownload: PropTypes.bool.isRequired,\n  canCompare: PropTypes.bool.isRequired,\n};\n\nclass MoreMenu extends React.PureComponent {\n\n  constructor(props) {\n    super(props);\n    this.state = {\n      dropdownOpen: false\n    };\n  }\n\n  dropdownToggle = () => {\n    this.setState({ dropdownOpen: !this.state.dropdownOpen });\n  }\n\n  render() {\n    const { index, downloadUrl, viewUrl, diffUrl, onItemRestore, canCompare, canDownload } = this.props;\n    return (\n      <Dropdown isOpen={this.state.dropdownOpen} toggle={this.dropdownToggle} direction=\"down\" className=\"mx-1 old-history-more-operation\">\n        <DropdownToggle\n          tag='i'\n          className='fa fa-ellipsis-v'\n          title={gettext('More Operations')}\n          data-toggle=\"dropdown\"\n          aria-expanded={this.state.dropdownOpen}\n        >\n        </DropdownToggle>\n        <DropdownMenu className=\"drop-list\" right={true}>\n          {index !== 0 && <a href=\"#\" onClick={onItemRestore}><DropdownItem>{gettext('Restore')}</DropdownItem></a>}\n          {canDownload && <a href={downloadUrl}><DropdownItem>{gettext('Download')}</DropdownItem></a>}\n          <a href={viewUrl}><DropdownItem>{gettext('View')}</DropdownItem></a>\n          {/*canCompare && <a href={diffUrl}><DropdownItem>{gettext('Diff')}</DropdownItem></a>*/}\n        </DropdownMenu>\n      </Dropdown>\n    );\n  }\n}\n\nMoreMenu.propTypes = MoreMenuPropTypes;\n\nexport default HistoryItem;\n","import React, { Fragment } from 'react';\nimport ReactDOM from 'react-dom';\nimport { Button } from 'reactstrap';\nimport { Utils } from './utils/utils';\nimport { seafileAPI } from './utils/seafile-api';\nimport { gettext, PER_PAGE, filePath, fileName, historyRepoID, useNewAPI, canDownload, canCompare } from './utils/constants';\nimport editUtilities from './utils/editor-utilities';\nimport Loading from './components/loading';\nimport Logo from './components/logo';\nimport CommonToolbar from './components/toolbar/common-toolbar';\nimport HistoryItem from './pages/file-history-old/history-item';\n\nimport './css/layout.css';\nimport './css/toolbar.css';\nimport './css/search.css';\nimport './css/file-history-old.css';\n\nclass FileHistory extends React.Component {\n\n  constructor(props) {\n    super(props);\n    this.state = {\n      historyList: [],\n      currentPage: 1,\n      hasMore: false,\n      nextCommit: undefined,\n      filePath: '',\n      oldFilePath: '',\n      isLoading: true,\n      isReloadingData: false,\n    };\n  }\n\n  componentDidMount() {\n    if (useNewAPI) {\n      this.listNewHistoryRecords(filePath, PER_PAGE);\n    } else {\n      this.listOldHistoryRecords(historyRepoID, filePath);\n    }\n  }\n\n  listNewHistoryRecords = (filePath, PER_PAGE) => {\n    editUtilities.listFileHistoryRecords(filePath, 1, PER_PAGE).then(res => {\n      let historyData = res.data;\n      if (!historyData) {\n        this.setState({isLoading: false});\n        throw Error('There is an error in server.');\n      }\n      this.initNewRecords(res.data);\n    });\n  }\n\n  listOldHistoryRecords = (repoID, filePath) => {\n    seafileAPI.listOldFileHistoryRecords(repoID, filePath).then((res) => {\n      let historyData = res.data;\n      if (!historyData) {\n        this.setState({isLoading: false});\n        throw Error('There is an error in server.');\n      }\n      this.initOldRecords(res.data);\n    });\n  }\n\n  initNewRecords(result) {\n    if (result.total_count < 5) {\n      if (result.data.length) {\n        let commitID = result.data[result.data.length-1].commit_id;\n        let path = result.data[result.data.length-1].path;\n        let oldPath = result.data[result.data.length-1].old_path;\n        path = oldPath ? oldPath : path;\n        seafileAPI.listOldFileHistoryRecords(historyRepoID, path, commitID).then((res) => {\n          if (!res.data) {\n            this.setState({isLoading: false});\n            throw Error('There is an error in server.');\n          }\n          this.setState({\n            historyList: result.data.concat(res.data.data.slice(1, res.data.data.length)),\n            isLoading: false,\n          });\n        });\n      } else {\n        seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath).then((res) => {\n          if (!res.data) {\n            this.setState({isLoading: false});\n            throw Error('There is an error in server.');\n          }\n          this.setState({\n            historyList: res.data.data,\n            isLoading: false,\n          });\n        });\n      }\n    } else {\n      this.setState({\n        historyList: result.data,\n        currentPage: result.page,\n        hasMore: result.total_count > (PER_PAGE * this.state.currentPage),\n        isLoading: false,\n      });\n    }\n  }\n\n  initOldRecords(result) {\n    if (result.data.length) {\n      this.setState({\n        historyList: result.data,\n        nextCommit: result.next_start_commit,\n        filePath: result.data[result.data.length-1].path,\n        oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,\n        isLoading: false,\n      });\n    } else {\n      this.setState({nextCommit: result.next_start_commit,});\n      if (this.state.nextCommit) {\n        seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, this.state.nextCommit).then((res) => {\n          this.initOldRecords(res.data);\n        });\n      } else {\n        this.setState({isLoading: false});\n      }\n    }\n  }\n\n  onScrollHandler = (event) => {\n    const clientHeight = event.target.clientHeight;\n    const scrollHeight = event.target.scrollHeight;\n    const scrollTop = event.target.scrollTop;\n    const isBottom = (clientHeight + scrollTop + 1 >= scrollHeight);\n    let hasMore = this.state.hasMore;\n    if (isBottom && hasMore) {\n      this.reloadMore();\n    }\n  }\n\n  reloadMore = () => {\n    if (!this.state.isReloadingData) {\n      if (useNewAPI) {\n        let currentPage = this.state.currentPage + 1;\n        this.setState({\n          currentPage: currentPage,\n          isReloadingData: true,\n        });\n        editUtilities.listFileHistoryRecords(filePath, currentPage, PER_PAGE).then(res => {\n          this.updateNewRecords(res.data);\n        });\n      } else {\n        let commitID = this.state.nextCommit;\n        let filePath = this.state.filePath;\n        let oldFilePath = this.state.oldFilePath;\n        this.setState({isReloadingData: true});\n        if (oldFilePath) {\n          seafileAPI.listOldFileHistoryRecords(historyRepoID, oldFilePath, commitID).then((res) => {\n            this.updateOldRecords(res.data, oldFilePath);\n          });\n        } else {\n          seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, commitID).then((res) => {\n            this.updateOldRecords(res.data, filePath);\n          });\n        }\n      }\n    }\n  }\n\n  updateNewRecords(result) {\n    this.setState({\n      historyList: [...this.state.historyList, ...result.data],\n      currentPage: result.page,\n      hasMore: result.total_count > (PER_PAGE * this.state.currentPage),\n      isReloadingData: false,\n    });\n  }\n\n  updateOldRecords(result, filePath) {\n    if (result.data.length) {\n      this.setState({\n        historyList: [...this.state.historyList, ...result.data],\n        nextCommit: result.next_start_commit,\n        filePath: result.data[result.data.length-1].path,\n        oldFilePath: result.data[result.data.length-1].rev_renamed_old_path,\n        isReloadingData: false,\n      });\n    } else {\n      this.setState({nextCommit: result.next_start_commit,});\n      if (this.state.nextCommit) {\n        seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath, this.state.nextCommit).then((res) => {\n          this.updateOldRecords(res.data, filePath);\n        });\n      }\n    }\n  }\n\n  onItemRestore = (item) => {\n    let commitId = item.commit_id;\n    let filePath = item.path;\n    editUtilities.revertFile(filePath, commitId).then(res => {\n      if (res.data.success) {\n        this.setState({isLoading: true});\n        this.refershFileList();\n      }\n    });\n  }\n\n  refershFileList() {\n    if (useNewAPI) {\n      editUtilities.listFileHistoryRecords(filePath, 1, PER_PAGE).then((res) => {\n        this.initNewRecords(res.data);\n      });\n    } else {\n      seafileAPI.listOldFileHistoryRecords(historyRepoID, filePath).then((res) => {\n        this.initOldRecords(res.data);\n      });\n    }\n  }\n\n  onSearchedClick = (searchedItem) => {\n    Utils.handleSearchedItemClick(searchedItem);\n  }\n\n  render() {\n    return (\n      <Fragment>\n        <div id=\"header\" className=\"old-history-header\">\n          <div className=\"logo\">\n            <Logo showCloseSidePanelIcon={false}/>\n          </div>\n          <div className='toolbar'>\n            <CommonToolbar onSearchedClick={this.onSearchedClick} />\n          </div>\n        </div>\n        <div id=\"main\" onScroll={this.onScrollHandler}>\n          <div className=\"old-history-main\">\n            <Fragment>\n              <a href=\"javascript:window.history.back()\" className=\"go-back\" title=\"Back\">\n                <span className=\"fas fa-chevron-left\"></span>\n              </a>\n              <h2><span className=\"file-name\">{fileName}</span>{' '}{gettext('History Versions')}</h2>\n            </Fragment>\n            <Fragment>\n              <table className=\"commit-list\">\n                <thead>\n                  <tr>\n                    <th width=\"40%\" >{gettext('Time')}</th>\n                    <th width=\"30%\" >{gettext('Modifier')}</th>\n                    <th width=\"25%\" >{gettext('Size')}</th>\n                    <th width=\"5%\" ></th>\n                  </tr>\n                </thead>\n                {!this.state.isLoading &&\n                  <tbody>\n                    {this.state.historyList.map((item, index) => {\n                      return (\n                        <HistoryItem\n                          key={index}\n                          item={item}\n                          index={index}\n                          canDownload={canDownload}\n                          canCompare={canCompare}\n                          onItemRestore={this.onItemRestore}\n                        />\n                      );\n                    })}\n                  </tbody>\n                }\n              </table>\n              {(this.state.isReloadingData || this.state.isLoading) && <Loading />}\n              {this.state.nextCommit && !this.state.isLoading && !this.state.isReloadingData &&\n                <Button className=\"get-more-btn\" onClick={this.reloadMore}>{gettext('More')}</Button>\n              }\n            </Fragment>\n          </div>\n        </div>\n      </Fragment>\n    );\n  }\n}\n\nReactDOM.render (\n  <FileHistory />,\n  document.getElementById('wrapper')\n);\n"],"sourceRoot":""}