Skip to content

Commit f894fe6

Browse files
committed
Improve url structure for budget items in dashboard
1 parent d196742 commit f894fe6

File tree

6 files changed

+55
-23
lines changed

6 files changed

+55
-23
lines changed

projects/budgetkey/src/app/dashboards/dashboard-search-results/dashboard-search-results.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class DashboardSearchResultsComponent {
2929
set selected(item) {
3030
console.log('config', this.api.baseRoute);
3131
if (item) {
32-
this.router.navigate([...this.api.baseRoute, item.doc_id.split('/').join('__')], {queryParamsHandling: 'preserve'});
32+
this.router.navigate([...this.api.baseRoute, item.doc_id], {queryParamsHandling: 'preserve'});
3333
} else {
3434
this.router.navigate(this.api.baseRoute, {queryParamsHandling: 'preserve'});
3535
}

projects/budgetkey/src/app/dashboards/dashboards-api.service.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { Subject, BehaviorSubject } from 'rxjs';
33
import { switchMap, debounceTime, map, distinctUntilChanged } from 'rxjs/operators';
44
import { HttpClient } from '@angular/common/http';
55
import { ActivatedRoute, Router } from '@angular/router';
6+
import { BudgetKeyItemService } from '../item/budgetkey-item.service';
67

78

8-
@Injectable({
9-
providedIn: 'root'
10-
})
9+
@Injectable()
1110
export class DashboardsApiService {
1211
public config: any = {};
1312
public baseRoute: string[] = [];
@@ -16,7 +15,7 @@ export class DashboardsApiService {
1615
searchResults = signal<any[]>([]);
1716
selectedItem = signal<any>(null);
1817

19-
constructor(private http: HttpClient, private router: Router) {
18+
constructor(private http: HttpClient, private router: Router, private bkis: BudgetKeyItemService) {
2019
this.searchQueue
2120
.pipe(
2221
distinctUntilChanged((x, y) => x.term === y.term),
@@ -39,12 +38,15 @@ export class DashboardsApiService {
3938
selectItem(doc_id: string | null) {
4039
console.log('selectItem', doc_id);
4140
if (doc_id) {
42-
doc_id = doc_id?.split('__').join('/');
4341
const url = `https://next.obudget.org/get/${doc_id}`;
4442
this.http
4543
.get(url)
4644
.subscribe((result: any) => {
47-
this.selectedItem.set(result.value);
45+
if (result.value?.__redirect) {
46+
this.selectItem(result.value.__redirect);
47+
} else {
48+
this.selectedItem.set(result.value);
49+
}
4850
});
4951
} else {
5052
this.selectedItem.set(null);
@@ -64,7 +66,7 @@ export class DashboardsApiService {
6466
map((r: any) => {
6567
const results: Array<any> = r.search_results || [];
6668
if (results.length === 1) {
67-
this.router.navigate([...this.baseRoute, results[0].source.doc_id.split('/').join('__')], {queryParamsHandling: 'preserve'});
69+
this.router.navigate([...this.baseRoute, results[0].source.doc_id.split('/')], {queryParamsHandling: 'preserve'});
6870
} else {
6971
if (this.selectedItem()) {
7072
this.selectedItem.set(null);
@@ -88,9 +90,7 @@ export class DashboardsApiService {
8890

8991
doQuery(query: string, item: any): any {
9092
query = this.formatQuery(query, item);
91-
const url = `https://next.obudget.org/api/query?query=${encodeURIComponent(query)}`;
92-
return this.http
93-
.get(url)
93+
return this.bkis.doQuery(query)
9494
.pipe(
9595
map((r: any) => r.rows)
9696
);

projects/budgetkey/src/app/dashboards/dashboards-page/dashboards-page.component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { config } from '../configurations/config';
66
import { DashboardSearchComponent } from '../dashboard-search/dashboard-search.component';
77
import { DashboardVisualizationsComponent } from '../dashboard-visualizations/dashboard-visualizations.component';
88
import { DashboardsApiService } from '../dashboards-api.service';
9+
import { map, tap } from 'rxjs';
10+
import { ItemModule } from '../../item/item.module';
911

1012
@UntilDestroy()
1113
@Component({
@@ -14,7 +16,8 @@ import { DashboardsApiService } from '../dashboards-api.service';
1416
imports: [
1517
ListComponentsModule,
1618
DashboardSearchComponent,
17-
DashboardVisualizationsComponent
19+
DashboardVisualizationsComponent,
20+
ItemModule
1821
],
1922
templateUrl: './dashboards-page.component.html',
2023
styleUrls: ['./dashboards-page.component.less']
@@ -25,13 +28,23 @@ export class DashboardsPageComponent {
2528
this.route.params.pipe(
2629
untilDestroyed(this)
2730
).subscribe(params => {
31+
console.log('params', params);
2832
this.api.config = config[params['config']];
2933
this.api.baseRoute = ['/dashboards', params['config']];
30-
if (params['item-id']) {
31-
this.api.selectItem(params['item-id']);
34+
});
35+
this.route.url.pipe(
36+
untilDestroyed(this),
37+
tap((url: any) => {
38+
console.log('url', url);
39+
}),
40+
map((url: any) => url.map((s: any) => s.path).join('/')),
41+
).subscribe((itemId: string) => {
42+
console.log('itemId', itemId);
43+
if (itemId && itemId.length) {
44+
this.api.selectItem(itemId);
3245
} else {
3346
this.api.selectItem(null);
3447
}
35-
});
48+
})
3649
}
3750
}

projects/budgetkey/src/app/dashboards/dashboards-routing.module.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ import { Routes, RouterModule } from "@angular/router";
33
import { DashboardsPageComponent } from "./dashboards-page/dashboards-page.component";
44

55
const routes: Routes = [
6-
{
7-
path: ':config/:item-id',
8-
component: DashboardsPageComponent
9-
},
106
{
117
path: ':config',
12-
component: DashboardsPageComponent
8+
children: [
9+
{
10+
path: '**',
11+
component: DashboardsPageComponent
12+
},
13+
{
14+
path: '',
15+
component: DashboardsPageComponent
16+
}
17+
]
1318
},
1419
];
1520

projects/budgetkey/src/app/dashboards/dashboards.module.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { CommonComponentsModule } from '../common-components/common-components.m
44
import { DashboardsPageComponent } from './dashboards-page/dashboards-page.component';
55
import { DashboardsRoutingModule } from './dashboards-routing.module';
66
import { ListComponentsModule } from '../list-components/list-components.module';
7+
import { ItemModule } from '../item/item.module';
8+
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
9+
import { DashboardsApiService } from './dashboards-api.service';
710

811

912

@@ -15,6 +18,10 @@ import { ListComponentsModule } from '../list-components/list-components.module'
1518
CommonComponentsModule,
1619
ListComponentsModule,
1720
DashboardsRoutingModule,
21+
ItemModule,
22+
],providers: [
23+
DashboardsApiService,
24+
provideHttpClient(withInterceptorsFromDi()),
1825
]
1926
})
2027
export class DashboardsModule { }

projects/budgetkey/src/app/item/budgetkey-item.service.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ export class BudgetKeyItemService {
9696
(this.globalSettings.themeId ? '&theme=' + this.globalSettings.themeId : '') + '">' + parts[2] + '</a>';
9797
}
9898

99-
getItemData(query: string, headersOrder: string[], formatters: any[], page = 0, pageSize?: number): Observable<object> {
99+
doQuery(query: string, page = 0, pageSize?: number): Observable<any> {
100100
if (this.ps.server()) {
101-
return from([{query, headers: [], items: [], total: 0, rows: [], error: null, pages: 0, page: 0}])
101+
return from([]);
102102
}
103103
const params: any = {
104104
page
@@ -109,7 +109,14 @@ export class BudgetKeyItemService {
109109
}
110110
const formData = new FormData();
111111
formData.append('query', query);
112-
return this.http.post(url, formData, {params})
112+
return this.http.post(url, formData, {params});
113+
}
114+
115+
getItemData(query: string, headersOrder: string[], formatters: any[], page = 0, pageSize?: number): Observable<object> {
116+
if (this.ps.server()) {
117+
return from([{query, headers: [], items: [], total: 0, rows: [], error: null, pages: 0, page: 0}])
118+
}
119+
return this.doQuery(query, page, pageSize)
113120
.pipe(
114121
map(
115122
(res: any) => {

0 commit comments

Comments
 (0)