Skip to content

Commit

Permalink
Supporting multi origin servers
Browse files Browse the repository at this point in the history
  • Loading branch information
cjmalloy committed Jul 28, 2022
1 parent 4673369 commit 5773b8a
Show file tree
Hide file tree
Showing 67 changed files with 955 additions and 402 deletions.
7 changes: 6 additions & 1 deletion src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { BackupComponent } from './component/backup/backup.component';
import { AdminPage } from './page/admin/admin.component';
import { AdminBackupPage } from './page/admin/backup/backup.component';
import { AdminOriginPage } from './page/admin/origin/origin.component';
import { AdminPluginPage } from './page/admin/plugin/plugin.component';
import { AdminSetupPage } from './page/admin/setup/setup.component';
import { AdminTemplatePage } from './page/admin/template/template.component';
import { CreateExtPage } from './page/create/ext/ext.component';
import { CreateOriginPage } from './page/create/origin/origin.component';
import { CreateProfilePage } from './page/create/profile/profile.component';
import { CreateUserPage } from './page/create/user/user.component';
import { HomePage } from './page/home/home.component';
Expand All @@ -17,10 +17,12 @@ import { InboxInvoicesPage } from './page/inbox/invoices/invoices.component';
import { InboxSentPage } from './page/inbox/sent/sent.component';
import { InboxUnreadPage } from './page/inbox/unread/unread.component';
import { LoginPage } from './page/login/login.component';
import { RefAltsComponent } from './page/ref/alts/alts.component';
import { RefCommentsComponent } from './page/ref/comments/comments.component';
import { RefGraphComponent } from './page/ref/graph/graph.component';
import { RefMissingComponent } from './page/ref/missing/missing.component';
import { RefPage } from './page/ref/ref.component';
import { RefRemotesComponent } from './page/ref/remotes/remotes.component';
import { RefResponsesComponent } from './page/ref/responses/responses.component';
import { RefSourcesComponent } from './page/ref/sources/sources.component';
import { SettingsExtPage } from './page/settings/ext/ext.component';
Expand Down Expand Up @@ -61,6 +63,8 @@ const routes: Routes = [
{ path: 'sources', redirectTo: 'sources/created', pathMatch: 'full' },
{ path: 'sources/:sort', component: RefSourcesComponent },
{ path: 'missing', component: RefMissingComponent },
{ path: 'alts', component: RefAltsComponent },
{ path: 'remotes', component: RefRemotesComponent },
{ path: 'graph', component: RefGraphComponent },
],
}, {
Expand All @@ -83,6 +87,7 @@ const routes: Routes = [
{ path: 'create/ext', component: CreateExtPage },
{ path: 'create/user', component: CreateUserPage },
{ path: 'create/profile', component: CreateProfilePage },
{ path: 'create/origin', component: CreateOriginPage },
{
path: 'admin',
component: AdminPage,
Expand Down
12 changes: 12 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ import { AutofocusDirective } from './directive/autofocus.directive';
import { MdPostDirective } from './directive/md-post.directive';
import { ResizeDirective } from './directive/resize.directive';
import { CodeComponent } from './form/code/code.component';
import { FeedFormComponent } from './form/feed/feed.component';
import { LinksFormComponent } from './form/links/links.component';
import { OriginFormComponent } from './form/origin/origin.component';
import { ArchiveFormComponent } from './form/plugin/archive/archive.component';
import { AudioFormComponent } from './form/plugin/audio/audio.component';
import { CommentFormComponent } from './form/plugin/comment/comment.component';
Expand All @@ -53,6 +55,7 @@ import { QtagsFormComponent } from './form/qtags/qtags.component';
import { QueriesFormComponent } from './form/queries/queries.component';
import { RefFormComponent } from './form/ref/ref.component';
import { TagsFormComponent } from './form/tags/tags.component';
import { UserFormComponent } from './form/user/user.component';
import { UsersFormComponent } from './form/users/users.component';
import { DebugInterceptor } from './http/debug.interceptor';
import { AdminPage } from './page/admin/admin.component';
Expand All @@ -61,6 +64,7 @@ import { AdminPluginPage } from './page/admin/plugin/plugin.component';
import { AdminSetupPage } from './page/admin/setup/setup.component';
import { AdminTemplatePage } from './page/admin/template/template.component';
import { CreateExtPage } from './page/create/ext/ext.component';
import { CreateOriginPage } from './page/create/origin/origin.component';
import { CreateProfilePage } from './page/create/profile/profile.component';
import { CreateUserPage } from './page/create/user/user.component';
import { HomePage } from './page/home/home.component';
Expand Down Expand Up @@ -100,6 +104,8 @@ import { ThemesFormComponent } from './form/themes/themes.component';
import { ListEditorComponent } from './component/list-editor/list-editor.component';
import { AdminBackupPage } from './page/admin/backup/backup.component';
import { BackupListComponent } from './component/backup-list/backup-list.component';
import { RefAltsComponent } from './page/ref/alts/alts.component';
import { RefRemotesComponent } from './page/ref/remotes/remotes.component';

const loadFactory = (config: ConfigService, admin: AdminService, account: AccountService) => () =>
config.load$.pipe(
Expand Down Expand Up @@ -137,6 +143,7 @@ const loadFactory = (config: ConfigService, admin: AdminService, account: Accoun
AutofocusDirective,
CreateExtPage,
CreateProfilePage,
CreateOriginPage,
EditTagPage,
LoadingComponent,
AdminPage,
Expand Down Expand Up @@ -197,6 +204,11 @@ const loadFactory = (config: ConfigService, admin: AdminService, account: Accoun
AdminBackupPage,
BackupComponent,
BackupListComponent,
UserFormComponent,
OriginFormComponent,
FeedFormComponent,
RefAltsComponent,
RefRemotesComponent,
],
imports: [
BrowserModule,
Expand Down
14 changes: 7 additions & 7 deletions src/app/component/comment/comment.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
[ref]="ref"
[commentEdited$]="commentEdited$"></app-comment-edit>
<div class="actions">
<a [routerLink]="['/ref', ref.url, 'comments']">permalink</a>
<a [routerLink]="['/ref', ref.url, 'responses']">{{ responses.replace(' ', '&thinsp;') }}</a>
<a [routerLink]="['/ref', ref.url, 'sources']">{{ sources.replace(' ', '&thinsp;')}}</a>
<a [routerLink]="['/ref', ref.url, 'comments']" [queryParams]="{ origin }">permalink</a>
<a [routerLink]="['/ref', ref.url, 'responses']" [queryParams]="{ origin }">{{ responses.replace(' ', '&thinsp;') }}</a>
<a [routerLink]="['/ref', ref.url, 'sources']" [queryParams]="{ origin }">{{ sources.replace(' ', '&thinsp;')}}</a>
<ng-container *ngIf="admin.status.plugins.graph">
<a [routerLink]="['/ref', ref.url, 'graph']" [queryParams]="{hideSearch: true}">graph</a>
<a [routerLink]="['/ref', ref.url, 'graph']" [queryParams]="{ origin, hideSearch: true }">graph</a>
</ng-container>
<a class="fake-link"
*ngIf="writeAccess$ | async"
Expand All @@ -61,7 +61,7 @@
<a class="fake-link" (click)="deleting = false">no</a>
</span>
<a class="fake-link"
*ngIf="account.editor || (writeAccess$ | async)"
*ngIf="!ref.origin && account.editor || (writeAccess$ | async)"
(click)="tagging = !tagging">tag</a>
<span *ngIf="tagging" class="inline-tagging">
<input #inlineTag
Expand All @@ -78,7 +78,7 @@
(click)="replying = !replying">reply</a>
<ng-container *ngIf="canInvoice">
<a [routerLink]="['/submit/invoice']"
[queryParams]="{url: ref.url}">invoice</a>
[queryParams]="{ url: ref.url }">invoice</a>
</ng-container>
<a *ngIf="account.mod && !approved"
class="fake-link"
Expand All @@ -100,7 +100,7 @@
</span>
<a class="load-more"
*ngIf="!collapsed && context >= maxContext && depth === 0 && ref.metadata!.plugins['plugin/comment'].length > 0"
[routerLink]="['/ref', ref.url, 'comments']">
[routerLink]="['/ref', ref.url, 'comments']" [queryParams]="{ origin }">
continue this thread
</a>
<div *ngIf="depth! > 0"
Expand Down
15 changes: 10 additions & 5 deletions src/app/component/comment/comment.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class CommentComponent implements OnInit, OnDestroy {
return this._ref;
}

get origin() {
return this._ref.origin || undefined;
}

@Input()
set ref(value: Ref) {
this._ref = value;
Expand Down Expand Up @@ -95,11 +99,12 @@ export class CommentComponent implements OnInit, OnDestroy {
}

get canInvoice() {
return this.admin.status.plugins.invoice &&
this.isAuthor &&
(this._ref.tags?.includes('plugin/comment') ||
!this._ref.tags?.includes('internal')) &&
this._ref.sources;
if (this._ref.origin) return false;
if (!this.admin.status.plugins.invoice) return false;
if (!this.isAuthor) return false;
if (!this._ref.sources || !this._ref.sources.length) return false;
return this._ref.tags?.includes('plugin/comment') ||
!this._ref.tags?.includes('internal');
}

get isAuthor() {
Expand Down
26 changes: 4 additions & 22 deletions src/app/component/feed/feed.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<a [routerLink]="['/tag', tag]">{{ tag }}</a>&nbsp;
</ng-container>
</ng-container>
<ng-container *ngIf="feed.origin">
on <a [routerLink]="['/tag', feed.origin]">{{ feed.origin }}</a>
</ng-container>
</div>
<div class="actions">
<a *ngIf="account.editor"
Expand Down Expand Up @@ -53,28 +56,7 @@

<form *ngIf="editing" class="form" [formGroup]="editForm" (ngSubmit)="save()">

<label for="name">Name:</label>
<input type="text" id="name" formControlName="name">

<label for="tags">Tags:</label>
<app-tags id="tags" [group]="editForm"></app-tags>

<label for="scrapeInterval">Scrape Interval:</label>
<input id="scrapeInterval" type="text" [formControl]="scrapeInterval">

<span><!-- Help --></span>
<div class="no-margin">
<span class="hints">
Use time spans (HH:MM:SS) or ISO 8601 Durations
<sup><a target="_blank" href="https://en.wikipedia.org/wiki/ISO_8601#Durations">help</a></sup>
</span>
</div>

<label for="scrapeDescription">Scrape Description:</label>
<input id="scrapeDescription" type="checkbox" [formControl]="scrapeDescription">

<label for="removeDescriptionIndent">Remove Description Indent:</label>
<input id="removeDescriptionIndent" type="checkbox" [formControl]="removeDescriptionIndent">
<app-feed-form [group]="editForm"></app-feed-form>

<ng-container *ngFor="let e of serverError">
<span><!-- Unexpected Error --></span>
Expand Down
46 changes: 10 additions & 36 deletions src/app/component/feed/feed.component.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, ElementRef, HostBinding, Input, OnInit, ViewChild } from '@angular/core';
import { FormArray, FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { FormBuilder, FormGroup } from '@angular/forms';
import * as _ from 'lodash';
import { catchError, switchMap, throwError } from 'rxjs';
import { feedForm, FeedFormComponent } from '../../form/feed/feed.component';
import { Feed } from '../../model/feed';
import { AccountService } from '../../service/account.service';
import { AdminService } from '../../service/admin.service';
import { FeedService } from '../../service/api/feed.service';
import { interestingTags, TAG_REGEX, TAG_REGEX_STRING, urlSummary } from '../../util/format';
import { interestingTags, TAG_REGEX_STRING, urlSummary } from '../../util/format';
import { printError } from '../../util/http';

@Component({
Expand Down Expand Up @@ -44,18 +46,15 @@ export class FeedComponent implements OnInit {
private feeds: FeedService,
private fb: FormBuilder,
) {
this.editForm = fb.group({
name: [''],
tags: fb.array([]),
scrapeInterval: ['00:15:00'],
scrapeDescription: [true],
removeDescriptionIndent: [false],
});
this.editForm = feedForm(fb);
}

@ViewChild(FeedFormComponent)
set refForm(value: FeedFormComponent) {
_.defer(() => value?.setFeed(this.feed));
}

ngOnInit(): void {
while (this.tagsForm.length < (this.feed?.tags?.length || 0)) this.addTag();
this.editForm.patchValue(this.feed);
}

get tags() {
Expand All @@ -66,10 +65,6 @@ export class FeedComponent implements OnInit {
return urlSummary(this.feed.url);
}

get tagsForm() {
return this.editForm.get('tags') as FormArray;
}

addInlineTag() {
if (!this.inlineTag) return;
const tag = (this.inlineTag.nativeElement.value as string).toLowerCase();
Expand All @@ -85,27 +80,6 @@ export class FeedComponent implements OnInit {
});
}

addTag(value = '') {
this.tagsForm.push(this.fb.control(value, [Validators.required, Validators.pattern(TAG_REGEX)]));
this.submitted = false;
}

removeTag(index: number) {
this.tagsForm.removeAt(index);
}

get scrapeInterval() {
return this.editForm.get('scrapeInterval') as FormControl;
}

get scrapeDescription() {
return this.editForm.get('scrapeDescription') as FormControl;
}

get removeDescriptionIndent() {
return this.editForm.get('removeDescriptionIndent') as FormControl;
}

save() {
this.submitted = true;
this.editForm.markAllAsTouched();
Expand Down
14 changes: 9 additions & 5 deletions src/app/component/origin/origin.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
</div>
<div class="stack">
<div class="info">
<span [title]="origin.modified?.toISOString()">modified {{ origin.modified?.fromNow() }}</span>&nbsp;
<span [title]="origin.lastScrape?.toISOString()">replicated to {{ origin.lastScrape?.fromNow() }}</span>
<span [title]="origin.modified?.toISOString()">modified {{ origin.modified?.fromNow() }}</span>
<ng-container *ngIf="origin.lastScrape">
<span [title]="origin.lastScrape.toISOString()"> last scraped {{ origin.lastScrape.fromNow() }} </span>
</ng-container>
<ng-container *ngIf="!origin.lastScrape">
not scraped yet
</ng-container>
</div>
<div class="actions">
<a *ngIf="account.admin"
Expand All @@ -20,10 +25,9 @@
</div>
</div>

<form *ngIf="editing" class="form" [formGroup]="editForm" (ngSubmit)="save()">
<form *ngIf="editing" [formGroup]="editForm" (ngSubmit)="save()">

<label for="name">Name:</label>
<input type="text" id="name" formControlName="name">
<app-origin-form [group]="editForm"></app-origin-form>

<ng-container *ngFor="let e of serverError">
<span><!-- Unexpected Error --></span>
Expand Down
14 changes: 9 additions & 5 deletions src/app/component/origin/origin.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Component, HostBinding, Input, OnInit } from '@angular/core';
import { Component, HostBinding, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import * as _ from 'lodash';
import { catchError, switchMap, throwError } from 'rxjs';
import { originForm, OriginFormComponent } from '../../form/origin/origin.component';
import { Origin } from '../../model/origin';
import { AccountService } from '../../service/account.service';
import { OriginService } from '../../service/api/origin.service';
Expand Down Expand Up @@ -33,13 +35,15 @@ export class OriginComponent implements OnInit {
private origins: OriginService,
private fb: FormBuilder,
) {
this.editForm = fb.group({
name: [''],
});
this.editForm = originForm(fb);
}

@ViewChild(OriginFormComponent)
set refForm(value: OriginFormComponent) {
_.defer(() => value?.setOrigin(this.origin));
}

ngOnInit(): void {
this.editForm.patchValue(this.origin);
}

save() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ describe('PageControlsComponent', () => {
first: false,
last: false,
number: 0,
numberOfElements: 0,
size: 0,
totalElements: 0,
totalPages: 0
Expand Down
Loading

0 comments on commit 5773b8a

Please sign in to comment.