@@ -5,10 +5,18 @@ import { DataFilter } from "./dataFilter.js";
55import { BACKENDURL , FRONTENDURL } from "./config.js" ;
66import { getLogger } from "./libs/logging.js" ;
77import { checkUsrInfo , eraseUsrInfo } from "./login.js" ;
8+ import { sleep } from "./libs/timeUtils.js" ;
89
910
10- // Global storage of the dataInfoList
11+ // Global storages ===========
12+ // the dataInfoList
1113var g_datalist : DataInfoT [ ] ;
14+ // last dataEntry with action shown
15+ var g_prevActEntry : null | DataEntryElement
16+
17+ interface DataEntryElement extends HTMLDivElement {
18+ dataInfo : DataInfoT
19+ }
1220
1321function render ( dataInfoList : DataInfoT [ ] ) {
1422
@@ -43,6 +51,99 @@ function initSearch(dataInfoList: DataInfoT[]){
4351}
4452
4553function showData ( dataInfoList : DataInfoT [ ] ) {
54+ function showEntryAct ( entry : DataEntryElement ) {
55+ if ( entry . querySelector ( "div.entryAct" ) ) {
56+ // If already has act entry, skip re-triggering this function
57+ return ;
58+ }
59+ // Add elements
60+ entry . innerHTML += `
61+ <div class="entryAct gradIn">
62+ </div>
63+ `
64+ const acts : HTMLInputElement [ ] = new Array ( )
65+ const entryFrame = entry . querySelector ( "div.entryAct" ) ! ;
66+ const actView = document . createElement ( "input" ) ;
67+ actView . value = "View"
68+ acts . push ( actView ) ;
69+ const actNote = document . createElement ( "input" ) ;
70+ actNote . value = "Note"
71+ acts . push ( actNote ) ;
72+ const actDiscuss = document . createElement ( "input" ) ;
73+ actDiscuss . value = "Discuss"
74+ acts . push ( actDiscuss ) ;
75+
76+ for ( const act of acts ) {
77+ act . type = "button" ;
78+ act . classList . add ( "smoothTrans" ) ;
79+ entryFrame . appendChild ( act ) ;
80+ }
81+
82+ // Set callbacks for the actions
83+ function getOpenFileFunction ( ) : ( ) => void {
84+ const uid = entry . dataInfo . uuid ;
85+ let destURL : string ;
86+ if ( entry . dataInfo [ "has_file" ] && entry . dataInfo [ "file_type" ] === ".pdf" ) {
87+ destURL = `${ BACKENDURL } /doc/${ uid } `
88+ }
89+ else if ( entry . dataInfo [ "has_file" ] && entry . dataInfo [ "file_type" ] === ".hpack" ) {
90+ destURL = `${ BACKENDURL } /doc/${ uid } //`
91+ }
92+ else if ( entry . dataInfo . url ) {
93+ destURL = entry . dataInfo . url ;
94+ }
95+ return ( ) => {
96+ // if (destURL) window.location.href = destURL;
97+ if ( destURL ) window . open ( destURL , '_blank' ) ?. focus ( ) ;
98+ }
99+ }
100+ function getOpenNoteFunction ( ) : ( ) => void {
101+ const uid = entry . dataInfo . uuid ;
102+ return ( ) => {
103+ const dest = `${ BACKENDURL } /comment/${ uid } /` ;
104+ // Simulate a mouse click:
105+ // it will somehow omit the last '/'
106+ // window.location.href = `${BACKENDURL}/comment/${uid}/`;
107+ //
108+ // Use this instead
109+ window . open ( dest , '_blank' ) ?. focus ( ) ;
110+ }
111+ }
112+ function getOpenDiscussionFunction ( ) : ( ) => void {
113+ const uid = entry . dataInfo . uuid ;
114+ return ( ) => {
115+ alert ( "Not implemented yet." )
116+ }
117+ }
118+ actView . addEventListener ( "click" , getOpenFileFunction ( ) ) ;
119+ actNote . addEventListener ( "click" , getOpenNoteFunction ( ) ) ;
120+ actDiscuss . addEventListener ( "click" , getOpenDiscussionFunction ( ) ) ;
121+
122+ // May be remove other entry frame
123+ if ( g_prevActEntry != null && g_prevActEntry . classList == entry . classList ) {
124+ // compare if prev activated entry is the current one
125+ // This may be unnecessary because we are not re-triggering this function
126+ // by previous condition checking
127+ getLogger ( 'rbm' ) . debug ( "Staying in same entry" ) ;
128+ }
129+ else {
130+ // Remove previous entry's action frame
131+ if ( g_prevActEntry ) {
132+ removeEntryAct ( g_prevActEntry ) ;
133+ }
134+ // save this as global
135+ g_prevActEntry = entry ;
136+ }
137+ }
138+ function removeEntryAct ( entry : HTMLDivElement ) {
139+ // remove entry action frame if it exists
140+ const actFrame = entry . querySelector ( "div.entryAct" ) ;
141+ if ( actFrame ) {
142+ entry . removeChild ( actFrame ) ;
143+ }
144+ }
145+
146+
46147 const selectorDiv : HTMLDivElement = document . querySelector ( "div.selector" ) ! ;
47148 // first, clear selector_frame
48149 removeChilds ( selectorDiv ) ;
@@ -51,41 +152,45 @@ function showData(dataInfoList: DataInfoT[]){
51152 // add valid data into it
52153 for ( const dataInfo of dataInfoList ) {
53154 idx += 1 ;
54- const dataEntry = document . createElement ( "div" ) ;
155+ const dataEntry = < DataEntryElement > document . createElement ( "div" ) ;
156+ dataEntry . dataInfo = dataInfo ;
55157 dataEntry . classList . add ( "dataEntry" ) ;
56158 dataEntry . innerHTML = `
57- <div class="yearAuthor">
58- <label class="year">${ dataInfo . year } </label>
59- <label class="author">${ dataInfo . author } </label>
159+ <div class="entryInfo">
160+ <div class="yearAuthor">
161+ <label class="year">${ dataInfo . year } </label>
162+ <label class="author">${ dataInfo . author } </label>
163+ </div>
164+ <label class="title">${ dataInfo . title } </label>
60165 </div>
61- <label class="title">${ dataInfo . title } </label>
62166 `
63167 selectorDiv . appendChild ( dataEntry ) ;
64168
65169 // animation property
66170 const delay = 0.05 * idx + Math . random ( ) * 0.1 ;
67171 dataEntry . classList . add ( "gradIn2" ) ;
68172 dataEntry . classList . add ( "smoothTrans" ) ;
69- dataEntry . classList . add ( "hoverMaxout105" ) ;
70- dataEntry . classList . add ( "hoverBlueWhite" ) ;
173+ dataEntry . classList . add ( "hoverMaxout103" ) ;
174+ // dataEntry.classList.add("hoverBlueWhite");
175+ dataEntry . classList . add ( dataInfo . uuid ) ;
71176 dataEntry . style . animationDelay = delay . toString ( ) + "s" ;
72177
73- // on click
74- function getOnClickFunction ( ) : ( ) => void {
75- const uid = dataInfo . uuid ;
76- let destURL : string ;
77- if ( dataInfo [ "has_file" ] && dataInfo [ "file_type" ] === ".pdf" ) {
78- destURL = `${ BACKENDURL } /doc/${ uid } `
79- }
80- else if ( dataInfo [ "has_file" ] && dataInfo [ "file_type" ] === ".hpack" ) {
81- destURL = `${ BACKENDURL } /doc/${ uid } `
82- }
83- return ( ) => {
84- if ( destURL ) window . location . href = destURL ;
85- }
86- }
87178
88- dataEntry . addEventListener ( "click" , getOnClickFunction ( ) ) ;
179+ dataEntry . addEventListener ( "mouseover" ,
180+ ( function ( ) { return ( ) => { showEntryAct ( dataEntry ) ; } } ) ( )
181+ )
182+ dataEntry . addEventListener ( "mouseleave" ,
183+ ( function ( ) {
184+ return async ( ) => {
185+ // to remove act frame when mouse move out of the entry
186+ // and not entering another entry
187+ // delay execution is used to resolve
188+ // flashing when hoveing betweeing two entries
189+ await sleep ( 200 ) ;
190+ removeEntryAct ( dataEntry ) ;
191+ }
192+ } ) ( )
193+ )
89194 }
90195}
91196
0 commit comments