File indexing completed on 2024-12-22 05:34:44

0001 window.appHelpers = (function(){
0002 
0003   function getHostNameSuffix(){
0004     let hostNameSuffix = "org";
0005     if (location.hostname.endsWith('cc')) {
0006       hostNameSuffix = "cc";
0007     } else if (location.hostname.endsWith('localhost')) {
0008       hostNameSuffix = "localhost";
0009     }
0010     return hostNameSuffix;
0011   }
0012 
0013   function generateTabsMenuArray(){
0014     const baseUrl = "https://www.opendesktop." + this.getHostNameSuffix();
0015     const tabsMenuArray = [
0016       {
0017         title:"Supporters",
0018         url:baseUrl + "/community/getjson?e=supporters"
0019       },{
0020         title:"Most plinged Creators",
0021         url:baseUrl + "/community/getjson?e=mostplingedcreators"
0022       },{
0023         title:"Most plinged Products",
0024         url:baseUrl + "/community/getjson?e=mostplingedproducts"
0025       },{
0026         title:"Recently plinged Products",
0027         url:baseUrl + "/community/getjson?e=plingedprojects"
0028       },{
0029         title:"New Members",
0030         url:baseUrl + "/community/getjson?e=newmembers"
0031       },{
0032         title:"Top Members",
0033         url:baseUrl + "/community/getjson?e=topmembers"
0034       },{
0035         title:"Top List Members",
0036         url:baseUrl + "/community/getjson?e=toplistmembers"
0037       }
0038     ];
0039     return tabsMenuArray;
0040   }
0041 
0042   function formatDate(dateString) {
0043     const monthNames = [
0044       "Jan", "Feb", "Mar",
0045       "Apr", "May", "Jun",
0046       "Jul", "Aug", "Sep",
0047       "Oct", "Nov", "Dec"
0048     ];
0049 
0050     const date = dateString.split(' ')[0];
0051     const year = date.split('-')[0];
0052     const month = date.split('-')[1];
0053     const day = date.split('-')[2];
0054     const monthNameIndex = parseInt(month) - 1;
0055     const monthName = monthNames[monthNameIndex];
0056 
0057     return monthName + ' ' + day + ' ' + year;
0058   }
0059 
0060   return {
0061     getHostNameSuffix,
0062     generateTabsMenuArray,
0063     formatDate
0064   }
0065 }());
0066 
0067 class CommunityPage extends React.Component {
0068   constructor(props){
0069         super(props);
0070         this.state = {
0071       headerData:window.json_data.data
0072     };
0073   }
0074 
0075   componentDidMount() {
0076     /*
0077       var json_data = <?=json_encode($this->json_data)?>; hier bekommest du die oberteil info
0078       tabs info top members https://www.opendesktop.cc
0079       hier ist supporters https://www.opendesktop.cc/community/getjson?e=supporters
0080       alle tab events sind hier. /var/www/ocs-webserver/application/modules/default/controllers/CommunityController.php
0081       getjsonAction
0082     */
0083   }
0084 
0085   render(){
0086     return(
0087       <div id="community-page">
0088         <div className="container">
0089           <CommunityPageHeader
0090             headerData={this.state.headerData}
0091           />
0092           <CommunityPageTabsContainer />
0093         </div>
0094       </div>
0095     );
0096   }
0097 }
0098 
0099 class CommunityPageHeader extends React.Component {
0100   constructor(props){
0101         super(props);
0102         this.state = {};
0103   }
0104 
0105   render(){
0106     return(
0107       <div id="community-page-header" className="head-wrap">
0108         <h1>Community</h1>
0109         <div id="community-page-header-banner" className="col-lg-5 col-md-5 col-sm-6 col-xs-8">
0110           <div id="header-banner-top">
0111             <div className="header-banner-row">
0112               <p>{this.props.headerData.countActiveMembers}</p>
0113               <span>contributors added</span>
0114             </div>
0115             <div className="header-banner-row">
0116               <p>{this.props.headerData.countProjects}</p>
0117               <span>products</span>
0118             </div>
0119           </div>
0120           <div id="header-banner-bottom">
0121             <div className="center">
0122               <a className="btn btn-native" href="/register">
0123                 Register
0124               </a>
0125               <span>to join the community</span>
0126             </div>
0127           </div>
0128         </div>
0129       </div>
0130     );
0131   }
0132 }
0133 
0134 class CommunityPageTabsContainer extends React.Component {
0135   constructor(props){
0136         super(props);
0137         this.state = {
0138       loading:true,
0139       tabs:window.appHelpers.generateTabsMenuArray(),
0140       selectedIndex:0
0141     };
0142     this.renderTabs = this.renderTabs.bind(this);
0143     this.getSelectedTabData = this.getSelectedTabData.bind(this);
0144     this.handleTabMenuItemClick = this.handleTabMenuItemClick.bind(this);
0145   }
0146 
0147   componentDidMount() {
0148     this.getSelectedTabData();
0149   }
0150 
0151   renderTabs(selectedIndex){
0152     if (!selectedIndex){ selectedIndex = 0; }
0153     const tabs = window.appHelpers.generateTabsMenuArray();
0154     this.setState({
0155       tabs:tabs,
0156       selectedIndex:selectedIndex
0157     },function(){
0158       this.getSelectedTabData();
0159     });
0160   }
0161 
0162   getSelectedTabData(){
0163     // get selected tab thing
0164     const self = this;
0165     const selectedTab = self.state.tabs[self.state.selectedIndex];
0166     $.ajax({url: selectedTab.url,cache: false}).done(function(response){
0167       self.setState({
0168         tabContent:{
0169           title:selectedTab.title,
0170           data:response.data
0171         },
0172         loading:false
0173       })
0174     });
0175   }
0176 
0177   handleTabMenuItemClick(itemIndex){
0178     this.setState({loading:true},function(){
0179       this.renderTabs(itemIndex);
0180     });
0181   }
0182 
0183   render(){
0184     const selectedIndex = this.state.selectedIndex;
0185     const tabsMenuDisplay = this.state.tabs.map((t,index) => (
0186       <CommunityPageTabMenuItem
0187         key={index}
0188         index={index}
0189         selectedIndex={selectedIndex}
0190         tab={t}
0191         onTabMenuItemClick={this.handleTabMenuItemClick}
0192       />
0193     ));
0194 
0195     let tabContent;
0196     if (this.state.loading){
0197 
0198       tabContent = (
0199         <div id="loading-container">
0200            <div className="ajax-loader"></div>
0201         </div>
0202       );
0203 
0204     } else if (this.state.loading === false){
0205 
0206       const data = this.state.tabContent.data;
0207 
0208       if (this.state.selectedIndex === 0 || this.state.selectedIndex === 4){
0209         tabContent = (
0210           <UsersTab selectedIndex={this.state.selectedIndex} items={data} />
0211         );
0212       } else if (this.state.selectedIndex === 1){
0213         tabContent = (
0214           <CreatorsTab  selectedIndex={this.state.selectedIndex} items={data} />
0215         );
0216       } else if (this.state.selectedIndex === 2 || this.state.selectedIndex === 3){
0217         tabContent = (
0218           <PlingedProductsTab selectedIndex={this.state.selectedIndex} items={data} />
0219         );
0220       } else if (this.state.selectedIndex === 5 || this.state.selectedIndex === 6){
0221         tabContent = (
0222           <MemberScoresTab selectedIndex={this.state.selectedIndex} items={data} />
0223         );
0224       }
0225 
0226     }
0227 
0228     return(
0229       <div id="community-page-tabs-container" className="body-wrap">
0230         <div id="tabs-menu">
0231           {tabsMenuDisplay}
0232         </div>
0233         <div id="tabs-content">
0234           {tabContent}
0235         </div>
0236       </div>
0237     );
0238   }
0239 }
0240 
0241 class CommunityPageTabMenuItem extends React.Component {
0242   constructor(props){
0243         super(props);
0244         this.state = {};
0245     this.onTabMenuItemClick = this.onTabMenuItemClick.bind(this);
0246   }
0247 
0248   onTabMenuItemClick(){
0249     this.props.onTabMenuItemClick(this.props.index);
0250   }
0251 
0252   render(){
0253     const activeCssClass = this.props.index === this.props.selectedIndex ? "active" : "";
0254     return(
0255       <div className={"tab-menu-item " + activeCssClass}>
0256         <a onClick={this.onTabMenuItemClick}>
0257           {this.props.tab.title}
0258         </a>
0259       </div>
0260     );
0261   }
0262 }
0263 
0264 class UsersTab extends React.Component {
0265   constructor(props){
0266         super(props);
0267         this.state = {};
0268   }
0269 
0270   render(){
0271     let usersDisplay;
0272     if (this.props.items && this.props.items.length > 0){
0273       const selectedIndex = this.props.selectedIndex;
0274       usersDisplay = this.props.items.map((user,index) => (
0275         <CommunityListItem
0276           key={index}
0277           index={index}
0278           selectedIndex={selectedIndex}
0279           item={user}
0280           type={'user'}
0281         />
0282       ));
0283     }
0284     return(
0285       <div className="community-tab card-list-display" id="supporters-tab">
0286         <ul>{usersDisplay}</ul>
0287       </div>
0288     );
0289   }
0290 }
0291 
0292 class CreatorsTab extends React.Component {
0293   constructor(props){
0294         super(props);
0295         this.state = {};
0296   }
0297 
0298   render(){
0299     let creatorsDisplay;
0300     if (this.props.items && this.props.items.length > 0){
0301       const selectedIndex = this.props.selectedIndex;
0302       creatorsDisplay = this.props.items.map((creator,index) => (
0303         <CommunityListItem
0304           key={index}
0305           item={creator}
0306           type={'creator'}
0307           index={index}
0308           selectedIndex={selectedIndex}
0309         />
0310       ))
0311     }
0312     return(
0313       <div className="community-tab top-list-display" id="most-pling-creators-tab">
0314         <ol>{creatorsDisplay}</ol>
0315       </div>
0316     );
0317   }
0318 }
0319 
0320 class PlingedProductsTab extends React.Component {
0321   constructor(props){
0322         super(props);
0323         this.state = {};
0324   }
0325 
0326   render(){
0327     let products;
0328     if (this.props.items && this.props.items.length > 0){
0329       const selectedIndex = this.props.selectedIndex;
0330       products = this.props.items.map((product,index) => (
0331         <CommunityListItem
0332           key={index}
0333           item={product}
0334           type={'product'}
0335           index={index}
0336           selectedIndex={selectedIndex}
0337         />
0338       ))
0339     }
0340 
0341     let productsDisplay,
0342         tabContainerCssClass;
0343     if (this.props.selectedIndex === 2){
0344       productsDisplay = (
0345         <ol>{products}</ol>
0346       );
0347       tabContainerCssClass = "top-list-display";
0348     } else if (this.props.selectedIndex === 3) {
0349       productsDisplay = (
0350         <ul>{products}</ul>
0351       );
0352       tabContainerCssClass = "card-list-display"
0353     }
0354     return(
0355       <div className={"community-tab " + tabContainerCssClass} id="most-pling-product-tab">
0356         {productsDisplay}
0357       </div>
0358     );
0359   }
0360 }
0361 
0362 class MemberScoresTab extends React.Component {
0363   constructor(props){
0364         super(props);
0365         this.state = {};
0366   }
0367 
0368   render(){
0369     let members;
0370     if (this.props.items && this.props.items.length > 0){
0371       const selectedIndex = this.props.selectedIndex;
0372       members = this.props.items.map((member,index) => (
0373         <CommunityListItem
0374           key={index}
0375           item={member}
0376           type={'score'}
0377           index={index}
0378           selectedIndex={selectedIndex}
0379         />
0380       ));
0381     }
0382 
0383     let membersDisplay,
0384         tabContainerCssClass;
0385     if (this.props.selectedIndex === 6){
0386       membersDisplay = (
0387         <ol>{members}</ol>
0388       );
0389       tabContainerCssClass = "top-list-display";
0390     } else if (this.props.selectedIndex === 5) {
0391       membersDisplay = (
0392         <ul>{members}</ul>
0393       );
0394       tabContainerCssClass = "card-list-display"
0395     }
0396 
0397     return(
0398       <div className={"community-tab " + tabContainerCssClass} id="score-tab">
0399         {membersDisplay}
0400       </div>
0401     );
0402   }
0403 }
0404 
0405 class CommunityListItem extends React.Component {
0406   constructor(props){
0407         super(props);
0408         this.state = {};
0409   }
0410 
0411   render(){
0412 
0413     const i = this.props.item;
0414 
0415     /* USER DISPLAY */
0416     const userDisplay = (
0417       <CommunityListItemUserDisplay
0418         selectedIndex={this.props.selectedIndex}
0419         item={i}
0420       />
0421     );
0422     /* /USER DISPLAY */
0423 
0424     /* PROJECT DISPLAY */
0425     let imageBaseUrl;
0426     if (i.image_small){
0427       imageBaseUrl = "https://cn.opendesktop."+window.appHelpers.getHostNameSuffix()+"/cache/167x167-0/img/"+i.image_small;
0428     }
0429 
0430     const projectDisplay = (
0431       <a href={"/p/"+i.project_id}>
0432         <div className="project">
0433           <figure><img src={imageBaseUrl}/></figure>
0434           <div className="project-info">
0435             <h3 className="project-title">{i.title} <span className="version">{i.version}</span></h3>
0436             <span className="cat-title">{i.catTitle}</span>
0437           </div>
0438         </div>
0439       </a>
0440     );
0441     /* /PROJECT DISPLAY */
0442 
0443     /* SCORE DISPLAY */
0444     const scoreDisplay = (
0445       <CommunityListItemScoreDisplay
0446         item={i}
0447       />
0448     );
0449     /* /SCORE DISPLAY */
0450 
0451     /* DISPLAY TEMPLATE */
0452     let displayTemplate;
0453     if (this.props.selectedIndex === 0 || this.props.selectedIndex === 4){
0454       displayTemplate = (
0455         <div className="list-item-template">
0456           {userDisplay}
0457         </div>
0458       );
0459     } else if (this.props.selectedIndex === 1){
0460       displayTemplate = (
0461         <div className="list-item-template">
0462           <div className="creator-wrapper">
0463             <div className="list-ranking">{this.props.index + 1}</div>
0464             {userDisplay}
0465             {scoreDisplay}
0466           </div>
0467         </div>
0468       );
0469     } else if (this.props.selectedIndex === 2 || this.props.selectedIndex === 3){
0470       displayTemplate = (
0471         <div className="list-item-template">
0472           <div className="creator-wrapper">
0473             <div className="left-side-section">
0474               <div className="list-ranking">{this.props.index + 1}</div>
0475               {projectDisplay}
0476             </div>
0477             <div className="right-side-section">
0478               {userDisplay}
0479               {scoreDisplay}
0480             </div>
0481           </div>
0482         </div>
0483       );
0484     } else if (this.props.selectedIndex === 5 || this.props.selectedIndex === 6){
0485       displayTemplate = (
0486         <div className="list-item-template">
0487           <div className="scored-wrapper">
0488             {userDisplay}
0489             <div className="list-ranking">
0490               <span className="rank">{this.props.index + 1}</span>
0491               <span className="sum-plings">{i.score}</span>
0492             </div>
0493           </div>
0494         </div>
0495       );
0496     }
0497     /* /DISPLAY TEMPLATE */
0498 
0499     return(
0500       <li className="list-item">
0501         {displayTemplate}
0502       </li>
0503     );
0504   }
0505 }
0506 
0507 class CommunityListItemUserDisplay extends React.Component {
0508   constructor(props){
0509         super(props);
0510         this.state = {
0511       showHoverDiv:false
0512     };
0513     this.handleImageLoaded = this.handleImageLoaded.bind(this);
0514     this.getImageElementDimensions = this.getImageElementDimensions.bind(this);
0515     this.handleMouseIn = this.handleMouseIn.bind(this);
0516     this.handleMouseOut = this.handleMouseOut.bind(this);
0517   }
0518 
0519   componentDidMount() {
0520     this.getImageElementDimensions();
0521     console.log(this.props.selectedIndex);
0522   }
0523 
0524   getImageElementDimensions(){
0525     const height = this.divElement.clientHeight;
0526     const width = this.divElement.clientWidth;
0527     this.setState({
0528       imgHeight:height,
0529       imgWidth:width
0530     });
0531   }
0532 
0533   handleMouseIn(){
0534     this.setState({
0535       showHoverDiv:true,
0536       loading:true
0537     },function(){
0538       const self = this;
0539       $.get('/member/' + this.props.item.member_id + '/tooltip/', function (res) {
0540         self.setState({userData:res.data,loading:false});
0541       });
0542     });
0543   }
0544 
0545   handleMouseOut(){
0546     this.setState({showHoverDiv:false});
0547   }
0548 
0549   handleImageLoaded(){
0550     this.getImageElementDimensions();
0551   }
0552 
0553   render(){
0554 
0555     const i = this.props.item;
0556 
0557     let userCreatedAt;
0558     if (i.created_at){
0559       userCreatedAt = window.appHelpers.formatDate(i.created_at);
0560     }
0561     let byDisplay;
0562     if (this.props.selectedIndex === 2){
0563       byDisplay = <span className="by">by</span>;
0564     }
0565 
0566     let userHoverDivDisplay;
0567     if (this.state.showHoverDiv){
0568       let infoDisplay;
0569       if (this.state.loading){
0570         infoDisplay = (
0571           <div className="user-hover-info">
0572             <div className="ajax-loader"></div>
0573           </div>
0574         )
0575       } else {
0576 
0577         const userData = this.state.userData;
0578 
0579         let locationDisplay;
0580         if (userData.countrycity){
0581           locationDisplay = (
0582             <span>
0583               <span className="glyphicon glyphicon-map-marker"></span>
0584               {userData.countrycity}
0585             </span>
0586           );
0587         }
0588 
0589         infoDisplay = (
0590           <div className="user-hover-info">
0591             <span className="username">
0592               {i.username} {locationDisplay}
0593             </span>
0594             <span>{userData.cntProjects} products</span>
0595             <span>{userData.totalComments} comments</span>
0596             <span>Liked {userData.cntLikesGave} products</span>
0597             <span>Got {userData.cntLikesGot} Likes <span className="glyphicon glyphicon-heart"></span></span>
0598             <span>Last time active: {userData.lastactive_at}</span>
0599             <span>Member since: {userData.created_at}</span>
0600           </div>
0601         )
0602       }
0603 
0604 
0605       const userHoverDivStyle = {
0606         "left":this.state.imgWidth + "px",
0607         "marginTop":(this.state.imgHeight / 2) + "px"
0608       }
0609 
0610 
0611       let userHoverCssClass = "";
0612       if (this.state.loading){
0613         userHoverCssClass = "loading-user"
0614       }
0615 
0616       userHoverDivDisplay = (
0617         <div className={"user-hover-display " + userHoverCssClass} style={userHoverDivStyle}>
0618           {infoDisplay}
0619         </div>
0620       );
0621     }
0622 
0623     let userNameDisplay;
0624     if (this.props.selectedIndex === 2){
0625       userNameDisplay = (
0626         <span
0627           ref={ (divElement) => this.divElement = divElement}
0628           onMouseOver={(e) => this.handleMouseIn(e)}
0629           onMouseOut={this.handleMouseOut}
0630           className="username">{byDisplay}{i.username}</span>
0631       )
0632     } else {
0633       userNameDisplay = (
0634         <span className="username">{byDisplay}{i.username}</span>
0635       )
0636     }
0637 
0638     return(
0639       <a href={"/u/"+i.username+"/"} className="user-display-container">
0640         <div className="user">
0641           <figure
0642             ref={ (divElement) => this.divElement = divElement}
0643             onMouseOver={(e) => this.handleMouseIn(e)}
0644             onMouseOut={this.handleMouseOut}>
0645             <img
0646               onLoad={this.handleImageLoaded}
0647               src={i.profile_image_url}/>
0648           </figure>
0649           {userNameDisplay}
0650           <span className="user-created">{userCreatedAt}</span>
0651         </div>
0652         {userHoverDivDisplay}
0653       </a>
0654     );
0655   }
0656 }
0657 
0658 class CommunityListItemScoreDisplay extends React.Component {
0659   constructor(props){
0660         super(props);
0661         this.state = {};
0662     this.handleMouseIn = this.handleMouseIn.bind(this);
0663     this.handleMouseOut = this.handleMouseOut.bind(this);
0664   }
0665 
0666   handleMouseIn(){
0667     this.setState({
0668       showHoverDiv:true,
0669       loading:true
0670     },function(){
0671       const self = this;
0672       $.get('/plings/tooltip/id/' + this.props.item.project_id, function (res) {
0673         console.log(res);
0674         self.setState({scoreUsers:res.data,loading:false});
0675       });
0676     });
0677   }
0678 
0679   handleMouseOut(){
0680     this.setState({showHoverDiv:false});
0681   }
0682 
0683   render(){
0684 
0685     let scoreUsersHoverDiv;
0686     if (this.state.showHoverDiv){
0687       let scoreUsersDisplay,
0688           scoreUsersHoverDivHeight;
0689       if (this.state.loading){
0690         scoreUsersDisplay = (
0691           <div className="score-users-display">
0692             <div className="ajax-loader"></div>
0693           </div>
0694         );
0695       } else {
0696         const scoreUsers = this.state.scoreUsers.map((su,index) => (
0697           <div className="score-user" key={index}>
0698             <figure>
0699               <img src={su.profile_image_url}/>
0700             </figure>
0701             <span>{su.username}</span>
0702           </div>
0703         ));
0704         const scoreUserNumRows = Math.ceil(this.state.scoreUsers.length / 4);
0705         scoreUsersHoverDivHeight = scoreUserNumRows * 70;
0706         scoreUsersDisplay = (
0707           <div className="score-users-display">
0708             {scoreUsers}
0709           </div>
0710         );
0711       }
0712       scoreUsersHoverDiv = (
0713         <div className="score-hover-container" style={{"top":"-" + scoreUsersHoverDivHeight / 2}}>
0714           {scoreUsersDisplay}
0715         </div>
0716       )
0717     }
0718 
0719     console.log(this.props.item);
0720 
0721     let scoreDisplay;
0722     if (this.props.selectedIndex === 2){
0723       scoreDisplay = (
0724         <span className="score"
0725           ref={ (divElement) => this.divElement = divElement}
0726           onMouseOver={this.handleMouseIn}
0727           onMouseOut={this.handleMouseOut}>
0728           <img src="/images/system/pling-btn-active.png"/>
0729           {this.props.item.laplace_score}
0730         </span>
0731       );
0732     } else {
0733       scoreDisplay = (
0734         <span className="score">
0735           <img src="/images/system/pling-btn-active.png"/>
0736           {this.props.item.cnt}
0737         </span>
0738       );
0739     }
0740 
0741     return(
0742       <div
0743         className="score-container">
0744         {scoreDisplay}
0745         {scoreUsersHoverDiv}
0746       </div>
0747     );
0748   }
0749 }
0750 
0751 ReactDOM.render(
0752     <CommunityPage />,
0753     document.getElementById('community-page-container')
0754 );