Skip to content

Commit de00be8

Browse files
Merge pull request #79 from zitrosolrac/implementingPythonBackEndFeature
Addressing python backend pagination, node backend pagination, and front end pagination.
2 parents fa82d5e + 5f64a3c commit de00be8

File tree

12 files changed

+346
-197
lines changed

12 files changed

+346
-197
lines changed

backend/iblapi.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,11 @@ def do_req(subpath):
172172
# construct kwargs
173173
kwargs = {'as_dict': True}
174174
limit = int(request.values['__limit']) if '__limit' in values else None
175-
order = request.values['__order'] if '__order' in values else None
175+
order = request.values['__order'] if '__order' in values else 'KEY ASC'
176+
page = int(request.values['__page']) if '__page' in values else 1
176177
proj = json.loads(request.values['__proj']) if '__proj' in values else None
177-
special_fields = ['__json', '__limit', '__order', '__proj', '__json_kwargs']
178-
for a in (v for v in values if v not in special_fields):
178+
special_fields = ['__json', '__limit', '__order', '__proj', '__json_kwargs', '__page']
179+
for a in (k for k, v in values.items() if k not in special_fields and v):
179180
# HACK: 'uuid' attrs -> UUID type (see also: datajoint-python #594)
180181
postargs[a] = UUID(values[a]) if 'uuid' in a else values[a]
181182
args = [postargs] if len(postargs) else []
@@ -186,9 +187,14 @@ def do_req(subpath):
186187
if '__json_kwargs' in values:
187188
json_kwargs = json.loads(request.values['__json_kwargs'])
188189
args = {} if not args else dj.AndList(args)
189-
kwargs = {k: v for k, v in (('as_dict', True,),
190-
('limit', limit,),
190+
if limit == None:
191+
kwargs = {k: v for k, v in (('as_dict', True,),
191192
('order_by', order,)) if v is not None}
193+
else:
194+
kwargs = {k: v for k, v in (('as_dict', True,),
195+
('limit', limit,),
196+
('order_by', order,),
197+
('offset', (page-1)*limit)) if v is not None}
192198
# 2) and dispatch
193199
app.logger.debug("args: '{}', kwargs: {}".format(args, kwargs))
194200
if obj not in reqmap:
@@ -216,8 +222,6 @@ def handle_q(subpath, args, proj, fetch_args=None, **kwargs):
216222
((session * subject * lab * user) & arg).proj(flist)
217223
'''
218224
app.logger.info("handle_q: subpath: '{}', args: {}".format(subpath, args))
219-
app.logger.info('key words: {}'.format(kwargs))
220-
221225
fetch_args = {} if fetch_args is None else fetch_args
222226
ret = []
223227
post_process = None
@@ -266,10 +270,12 @@ def handle_q(subpath, args, proj, fetch_args=None, **kwargs):
266270

267271
q = ((acquisition.Session() * sess_proj * psych_curve * ephys_data * subject.Subject() *
268272
subject.SubjectLab() * subject.SubjectUser() * trainingStatus) & args & brain_restriction)
269-
273+
q = q.proj(*proj) if proj else q
270274
dj.conn().query("SET SESSION max_join_size={}".format('18446744073709551615'))
271-
q = q.proj(*proj).fetch(**fetch_args) if proj else q.fetch(**fetch_args)
275+
ret_count = len(q)
276+
ret = q.fetch(**fetch_args)
272277
dj.conn().query("SET SESSION max_join_size={}".format(original_max_join_size))
278+
return dumps({"records_count": ret_count, "records": ret})
273279
elif subpath == 'subjpage':
274280
proj_restr = None
275281
for e in args:

docker-compose-base.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
iblapi:
1010
<<: *net
1111
# image: registry.vathes.com/ibl-navigator/iblapi:v0.5.3 # for internal demo
12-
image: registry.vathes.com/ibl-navigator/iblapi:v0.2.1-public # for public demo
12+
image: registry.vathes.com/ibl-navigator/iblapi:v0.3.1-public # for public demo
1313
environment:
1414
# for internal djcompute
1515
# - DJ_USER=maho
@@ -33,7 +33,7 @@ services:
3333
ibl-navigator:
3434
<<: *net
3535
# image: registry.vathes.com/ibl-navigator/frontend:v0.4.2 # for internal demo
36-
image: registry.vathes.com/ibl-navigator/frontend:v0.2.6-public # for public demo
36+
image: registry.vathes.com/ibl-navigator/frontend:v0.3.2-public # for public demo
3737
healthcheck:
3838
test: curl --fail http://localhost:9000 || exit 1
3939
timeout: 3s
@@ -42,7 +42,7 @@ services:
4242
<<: *net
4343
platform: linux/amd64
4444
# image: registry.vathes.com/ibl-navigator/node-server:v0.3.0 # for internal demo
45-
image: registry.vathes.com/ibl-navigator/node-server:v0.2.1-public # for public demo
45+
image: registry.vathes.com/ibl-navigator/node-server:v0.3.1-public # for public demo
4646
environment:
4747
- NODE_ENV=development
4848
- DEMO_USERNAME=ibluser

ibl-frontend/Dockerfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
FROM vathes/angulardev:angcli7.1.4-angbuild0.11.4
1+
# FROM vathes/angulardev:angcli7.1.4-angbuild0.11.4
22

3+
FROM node:12-bullseye
34

5+
RUN \
6+
apt update && \
7+
apt install nginx -y
48

59
WORKDIR /app/dist/pipeline-viewer
610

@@ -12,11 +16,10 @@ COPY ./app.conf /etc/nginx/conf.d/default.conf
1216
CMD ["nginx", "-g", "daemon off;"]
1317

1418
ADD ./frontend-content/package.json /app/
15-
ADD ./frontend-content/package-lock.json /app/
19+
1620
RUN \
1721
cd /app && \
18-
npm install --save-dev @angular-devkit/build-angular > /dev/null
19-
22+
npm install
2023

2124
ADD ./frontend-content /app
2225

@@ -25,7 +28,7 @@ COPY ./frontend-content/src/assets/addons/plotly.js /app/node_modules/plotly.js-
2528

2629
RUN \
2730
cd /app && \
28-
node --max_old_space_size=8192 /usr/local/lib/node_modules/@angular/cli/bin/ng build --prod
31+
node --max_old_space_size=5120 /app/node_modules/@angular/cli/bin/ng build --configuration production
2932

3033

3134
# CMD ["http-server","-p", "8080" ,"-a","0.0.0.0"]

ibl-frontend/dev.dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ HEALTHCHECK \
1212
COPY ./entrypoint.sh /entrypoint.sh
1313
RUN chmod +x /entrypoint.sh
1414
ENTRYPOINT ["/entrypoint.sh"]
15-
# CMD tail -f /dev/null
1615

1716
WORKDIR /app
1817

1918
ADD ./frontend-content/package.json /app/
20-
#ADD ./frontend-content/package-lock.json /app/
2119
RUN \
2220
npm install && \
2321
npm install --only=dev
@@ -27,8 +25,8 @@ COPY ./frontend-content/src/assets/addons/indigo-pink-ibl.css /app/node_modules/
2725
COPY ./frontend-content/src/assets/addons/plotly.js /app/node_modules/plotly.js-dist/
2826

2927
CMD ["node", "--max_old_space_size=5120", "/app/node_modules/@angular/cli/bin/ng", "serve", "--host", "0.0.0.0", "--port", "9000", "--disable-host-check"]
30-
# /app/node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --port 9000 --disable-host-check
31-
# /app/node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --port 9000 --disable-host-check 1> /app/src/output.log 2> /app/src/error.log
28+
29+
# node --max_old_space_size=5120 /app/node_modules/@angular/cli/bin/ng serve --host 0.0.0.0 --port 9000 --disable-host-check 1> /app/src/output.log 2> /app/src/error.log
3230

3331

3432

ibl-frontend/frontend-content/angular.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
"input": "src/assets/fonts/css/open-iconic-bootstrap.min.css",
3232
"inject": true
3333
},
34-
"node_modules/@angular/material/prebuilt-themes/indigo-pink-ibl.css",
35-
"src/assets/fonts/css/open-iconic-bootstrap.min.css",
3634
"src/styles.css"
3735
],
3836
"scripts": [
@@ -64,7 +62,7 @@
6462
{
6563
"type": "initial",
6664
"maximumWarning": "2mb",
67-
"maximumError": "7mb"
65+
"maximumError": "10mb"
6866
},
6967
{
7068
"type": "anyComponentStyle",

ibl-frontend/frontend-content/src/app/app.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { PsthPlotsComponent } from './cell-list/cell/psth-plots/psth-plots.compo
6464
import { QualityControlComponent } from './quality-control/quality-control.component';
6565
import { DriftmapComponent } from './quality-control/driftmap/driftmap.component';
6666
import { SpinningBrainComponent } from './mouse-list/mouse/spinning-brain/spinning-brain.component';
67+
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
6768

6869
PlotlyModule.plotlyjs = PlotlyJS;
6970

@@ -154,7 +155,7 @@ const appRoutes: Routes = [
154155
FormsModule,
155156
HttpClientModule,
156157
RouterModule.forRoot(appRoutes),
157-
MatSelectModule, MatAutocompleteModule, MatIconModule, MatInputModule,
158+
MatSelectModule, MatAutocompleteModule, MatIconModule, MatInputModule, MatProgressSpinnerModule,
158159
MatCheckboxModule, MatRadioModule, MatNativeDateModule, MatDatepickerModule, MatMomentDateModule, MatSlideToggleModule,
159160
MatCardModule, MatButtonModule, MatTableModule, MatPaginatorModule, MatSortModule, MatSliderModule, MatExpansionModule,
160161
MatDialogModule, ReactiveFormsModule, FlexLayoutModule, MatTreeModule, MatFormFieldModule

ibl-frontend/frontend-content/src/app/session-list/all-sessions.service.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
11
import { Injectable } from '@angular/core';
2-
import { Subject } from 'rxjs';
2+
import { Subject, Observable } from 'rxjs';
33
import { HttpClient } from '@angular/common/http';
4-
54
import { environment } from '../../environments/environment';
65

76

87
const BACKEND_API_URL = environment.backend_url;
98

9+
export interface SessionRecord {
10+
mouse_id: number;
11+
session_date: string;
12+
session_lab: string;
13+
subject_nickname: string;
14+
subject_birth_date: string;
15+
session_start_time: string;
16+
task_protocol: string;
17+
subject_line: string;
18+
responsible_user: string;
19+
session_uuid: string;
20+
sex: string;
21+
subject_uuid: string;
22+
nplot: string;
23+
nprobe: string;
24+
session_project: string;
25+
good4bmap: string;
26+
}
27+
28+
interface SessionApi {
29+
records: SessionRecord[];
30+
records_count: number;
31+
}
32+
1033
@Injectable({
1134
providedIn: 'root'
1235
})
@@ -36,6 +59,11 @@ export class AllSessionsService {
3659
return this.http.post(BACKEND_API_URL + '/sessions/', sessionFilters, { responseType: 'json'})
3760
}
3861

62+
getSessions(body: Object): Observable<SessionApi> {
63+
const requestUrl = BACKEND_API_URL + '/sessions';
64+
return this.http.post<SessionApi>(requestUrl, body, { responseType: 'json' });
65+
}
66+
3967
getAllSessions() {
4068
let start = new Date();
4169
this.http.get(BACKEND_API_URL + `/sessions`)
@@ -88,7 +116,7 @@ export class AllSessionsService {
88116
(filteredSessionsData) => {
89117
let end = new Date();
90118
// console.log(`It took ${Number(end) - Number(start)}ms to retrieve the session list information`)
91-
this.retrievedSessions = filteredSessionsData;
119+
this.retrievedSessions = filteredSessionsData['records'];
92120
// console.log('retrievedSessions data are: ');
93121
// console.log(this.retrievedSessions);
94122
this.newSessionsLoaded.next(this.retrievedSessions);

ibl-frontend/frontend-content/src/app/session-list/session-list.component.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ label {
101101
display: none;
102102
}
103103

104+
.session-list-loading-shade {
105+
position: absolute;
106+
/* top: 0; */
107+
left: 0;
108+
/* bottom: 56px; */
109+
right: 0;
110+
background: rgba(0, 0, 0, 0.15);
111+
z-index: 9;
112+
display: flex;
113+
align-items: center;
114+
justify-content: center;
115+
height: 100%;
116+
}
117+
104118
.session-list-loading-message.show {
105119
display: block;
106120
}
@@ -122,6 +136,7 @@ label {
122136

123137
.table-container {
124138
width: 100%;
139+
position: relative;
125140
overflow-x: auto;
126141
}
127142
td.mat-cell,

ibl-frontend/frontend-content/src/app/session-list/session-list.component.html

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ <h4>
3131
</mat-form-field>
3232

3333
<div class="session-date-filter">
34+
<mat-form-field class="short" *ngIf="!isSessionDateUsingRange">
35+
<label for="">Sessions On</label>
36+
<input matInput formControlName="session_start_time" [matDatepicker]="datePicker" [min]="sessionMinDate" [max]="sessionMaxDate" [matDatepickerFilter]="sessionDateFilter" (blur)="updateMenu()" (focus)="stepBackMenu($event)">
37+
<mat-datepicker-toggle matSuffix [for]="datePicker"></mat-datepicker-toggle>
38+
<mat-datepicker #datePicker></mat-datepicker>
39+
</mat-form-field>
40+
</div>
41+
42+
<!-- <div class="session-date-filter">
3443
<div class="date-range-toggler">
3544
<label for="isSessionDateUsingRanger">Session Start Date</label>
3645
<div>
@@ -62,8 +71,7 @@ <h4>
6271
<mat-datepicker #datePickerSRE></mat-datepicker>
6372
</mat-form-field>
6473
</div>
65-
</div>
66-
74+
</div> -->
6775
</div>
6876
<div class="mouse-field-filters form-section">
6977
<mat-form-field>
@@ -153,7 +161,7 @@ <h4>
153161
<label>Brain Regions</label>
154162
<input matInput (input)="filterChanged($event.target.value.toLowerCase())">
155163
</mat-form-field>
156-
<div>Selected Brain Region:
164+
<!-- <div>Selected Brain Region:
157165
<div class="chip-list">
158166
<div class="selected-chip" *ngFor="let item of requested_BR">
159167
<div>{{ item }}</div>
@@ -164,16 +172,16 @@ <h4>
164172
165173
<div class="br-selection-area">
166174
<mat-tree [dataSource]="treeDataSource" [treeControl]="treeControl" class="brain-tree">
167-
<!-- // This is the tree node template for leaf nodes -->
175+
// This is the tree node template for leaf nodes
168176
<mat-nested-tree-node *matTreeNodeDef="let node" matTreeNodeToggle>
169177
<li class="mat-tree-node">
170-
<!-- // use a disabled button to provide padding for tree leaf -->
178+
// use a disabled button to provide padding for tree leaf
171179
<button class="treeChevron" mat-icon-button disabled></button>
172180
<mat-checkbox (change)="selectionToggle($event.checked, node)"
173181
[checked]="BT_allSelected(node)">{{node.display}}</mat-checkbox>
174182
</li>
175183
</mat-nested-tree-node>
176-
<!-- // This is the tree node template for expandable nodes -->
184+
// This is the tree node template for expandable nodes
177185
<mat-nested-tree-node *matTreeNodeDef="let node; when: BT_hasChild">
178186
<li>
179187
<div class="mat-tree-node">
@@ -193,7 +201,7 @@ <h4>
193201
</li>
194202
</mat-nested-tree-node>
195203
</mat-tree>
196-
</div>
204+
</div> -->
197205
</div>
198206

199207
</div>
@@ -211,7 +219,7 @@ <h4>
211219
<button mat-raised-button class="btn btn-refresh" (click)="refreshData()">Refresh Data</button>
212220
</div>
213221
</div>
214-
<div class="checkbox-filters">
222+
<!-- <div class="checkbox-filters">
215223
<div class="chbox-filter">
216224
<mat-checkbox class="nplot_status_chbox" [checked]="hideMissingPlots" (change)="toggleNplotStatus()">
217225
Only show sessions with behavior plots
@@ -227,19 +235,20 @@ <h4>
227235
Only show sessions with ephys data
228236
</mat-checkbox>
229237
</div>
230-
</div>
238+
</div> -->
231239
</div>
232240
</form>
233241

234242
<div [class]="isLoading && initialLoad ? 'loading-icon loading initial': isLoading ? 'loading-icon loading': 'loading-icon'">
235243
<img src="assets/images/loading_icon.gif">
236-
<p [class]="initialLoad ? 'session-list-loading-message show' : 'session-list-loading-message'">
237-
Loading for the sessions may take a while depending on your internet connection. We appreciate your patience as we load the full list of sessions.
238-
</p>
244+
<p [class]="initialLoad ? 'session-list-loading-message show' : 'session-list-loading-message'"></p>
239245
</div>
240246
<div class="table-container">
241-
<table mat-table class="col-12" [dataSource]="dataSource" matSort (matSortChange)="storeTableInfo($event)">
242-
247+
<div class="session-list-loading-shade"
248+
*ngIf="isLoadingTable">
249+
<mat-spinner *ngIf="isLoadingTable"></mat-spinner>
250+
</div>
251+
<table mat-table class="col-12" [dataSource]="sessionRecords" matSort (matSortChange)="storeTableInfo($event)">
243252
<ng-container matColumnDef="session_lab">
244253
<th mat-header-cell *matHeaderCellDef mat-sort-header> Lab </th>
245254
<td mat-cell *matCellDef="let session"> {{session.session_lab}} </td>
@@ -321,7 +330,8 @@ <h4>
321330
</table>
322331
</div>
323332

324-
<mat-paginator [pageSize]="pageSize"
333+
<mat-paginator [length]="sessionRecordLength"
334+
[pageSize]="pageSize"
325335
[pageSizeOptions]="pageSizeOptions"
326336
showFirstLastButtons (page)="storeTableInfo($event)"></mat-paginator>
327337
</div>

0 commit comments

Comments
 (0)