Design follow admin page

This commit is contained in:
Chocobozzz 2017-12-08 15:22:57 +01:00
parent cd83ea1b90
commit e600e1fea2
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
14 changed files with 73 additions and 114 deletions

View File

@ -1,5 +1,3 @@
<h3>Followers list</h3>
<p-dataTable <p-dataTable
[value]="followers" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage" [value]="followers" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
sortField="createdAt" (onLazyLoad)="loadLazy($event)" sortField="createdAt" (onLazyLoad)="loadLazy($event)"

View File

@ -1,3 +0,0 @@
.btn {
margin-top: 10px;
}

View File

@ -1,30 +1,22 @@
<h3>Add following</h3>
<div *ngIf="error" class="alert alert-danger">{{ error }}</div> <div *ngIf="error" class="alert alert-danger">{{ error }}</div>
<form (ngSubmit)="addFollowing()" [formGroup]="form"> <form (ngSubmit)="addFollowing()">
<div class="form-group" *ngFor="let host of hosts; let id = index; trackBy:customTrackBy"> <div class="form-group">
<label [for]="'host-' + id">Host (so without "http://")</label> <label for="hosts">1 host (without "http://") per line</label>
<div class="input-group"> <textarea
<input type="text" class="form-control" placeholder="example.com" id="hosts" name="hosts"
type="text" class="form-control" placeholder="example.com" [(ngModel)]="hostsString" (ngModelChange)="onHostsChanged()" [ngClass]="{ 'input-error': hostsError }"
[id]="'host-' + id" [formControlName]="'host-' + id" ></textarea>
/>
<span class="input-group-btn">
<button *ngIf="displayAddField(id)" (click)="addField()" class="btn btn-default" type="button">+</button>
<button *ngIf="displayRemoveField(id)" (click)="removeField(id)" class="btn btn-default" type="button">-</button>
</span>
</div>
<div [hidden]="form.controls['host-' + id].valid || form.controls['host-' + id].pristine" class="alert alert-warning"> <div *ngIf="hostsError" class="form-error">
It should be a valid host. {{ hostsError }}
</div> </div>
</div> </div>
<div *ngIf="canMakeFriends() === false" class="alert alert-warning"> <div *ngIf="httpEnabled() === false" class="alert alert-warning">
It seems that you are not on a HTTPS server. Your webserver need to have TLS activated in order to follow servers. It seems that you are not on a HTTPS server. Your webserver needs to have TLS activated in order to follow servers.
</div> </div>
<input type="submit" value="Add following" class="btn btn-default" [disabled]="!isFormValid()"> <input type="submit" value="Add following" [disabled]="hostsError || !hostsString" class="btn btn-default">
</form> </form>

View File

@ -1,7 +1,9 @@
table { textarea {
margin-bottom: 40px; height: 250px;
} }
.input-group-btn button { input[type=submit] {
width: 35px; @include peertube-button;
@include orange-button;
} }

View File

@ -1,9 +1,6 @@
import { Component, OnInit } from '@angular/core' import { Component } from '@angular/core'
import { FormControl, FormGroup } from '@angular/forms'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { NotificationsService } from 'angular2-notifications' import { NotificationsService } from 'angular2-notifications'
import { ConfirmService } from '../../../core' import { ConfirmService } from '../../../core'
import { validateHost } from '../../../shared' import { validateHost } from '../../../shared'
import { FollowService } from '../shared' import { FollowService } from '../shared'
@ -13,9 +10,9 @@ import { FollowService } from '../shared'
templateUrl: './following-add.component.html', templateUrl: './following-add.component.html',
styleUrls: [ './following-add.component.scss' ] styleUrls: [ './following-add.component.scss' ]
}) })
export class FollowingAddComponent implements OnInit { export class FollowingAddComponent {
form: FormGroup hostsString = ''
hosts: string[] = [ ] hostsError: string = null
error: string = null error: string = null
constructor ( constructor (
@ -25,76 +22,50 @@ export class FollowingAddComponent implements OnInit {
private followService: FollowService private followService: FollowService
) {} ) {}
ngOnInit () { httpEnabled () {
this.form = new FormGroup({})
this.addField()
}
addField () {
this.form.addControl(`host-${this.hosts.length}`, new FormControl('', [ validateHost ]))
this.hosts.push('')
}
canMakeFriends () {
return window.location.protocol === 'https:' return window.location.protocol === 'https:'
} }
customTrackBy (index: number, obj: any): any { onHostsChanged () {
return index this.hostsError = null
}
displayAddField (index: number) { const newHostsErrors = []
return index === (this.hosts.length - 1) const hosts = this.getNotEmptyHosts()
}
displayRemoveField (index: number) { for (const host of hosts) {
return (index !== 0 || this.hosts.length > 1) && index !== (this.hosts.length - 1) if (validateHost(host) === false) {
} newHostsErrors.push(`${host} is not valid`)
isFormValid () {
// Do not check the last input
for (let i = 0; i < this.hosts.length - 1; i++) {
if (!this.form.controls[`host-${i}`].valid) return false
}
const lastIndex = this.hosts.length - 1
// If the last input (which is not the first) is empty, it's ok
if (this.hosts[lastIndex] === '' && lastIndex !== 0) {
return true
} else {
return this.form.controls[`host-${lastIndex}`].valid
} }
} }
removeField (index: number) { if (newHostsErrors.length !== 0) {
// Remove the last control this.hostsError = newHostsErrors.join('. ')
this.form.removeControl(`host-${this.hosts.length - 1}`) }
this.hosts.splice(index, 1)
} }
addFollowing () { addFollowing () {
this.error = '' this.error = ''
const notEmptyHosts = this.getNotEmptyHosts() const hosts = this.getNotEmptyHosts()
if (notEmptyHosts.length === 0) { if (hosts.length === 0) {
this.error = 'You need to specify at least 1 host.' this.error = 'You need to specify hosts to follow.'
return
} }
if (!this.isHostsUnique(notEmptyHosts)) { if (!this.isHostsUnique(hosts)) {
this.error = 'Hosts need to be unique.' this.error = 'Hosts need to be unique.'
return return
} }
const confirmMessage = 'Are you sure to make friends with:<br /> - ' + notEmptyHosts.join('<br /> - ') const confirmMessage = 'If you confirm, you will send a follow request to:<br /> - ' + hosts.join('<br /> - ')
this.confirmService.confirm(confirmMessage, 'Follow new server(s)').subscribe( this.confirmService.confirm(confirmMessage, 'Follow new server(s)').subscribe(
res => { res => {
if (res === false) return if (res === false) return
this.followService.follow(notEmptyHosts).subscribe( this.followService.follow(hosts).subscribe(
status => { status => {
this.notificationsService.success('Success', 'Follow request(s) sent!') this.notificationsService.success('Success', 'Follow request(s) sent!')
this.router.navigate([ '/admin/follows/following-list' ])
setTimeout(() => this.router.navigate([ '/admin/follows/following-list' ]), 500)
}, },
err => this.notificationsService.error('Error', err.message) err => this.notificationsService.error('Error', err.message)
@ -103,18 +74,15 @@ export class FollowingAddComponent implements OnInit {
) )
} }
private getNotEmptyHosts () {
const notEmptyHosts = []
Object.keys(this.form.value).forEach((hostKey) => {
const host = this.form.value[hostKey]
if (host !== '') notEmptyHosts.push(host)
})
return notEmptyHosts
}
private isHostsUnique (hosts: string[]) { private isHostsUnique (hosts: string[]) {
return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host)) return hosts.every(host => hosts.indexOf(host) === hosts.lastIndexOf(host))
} }
private getNotEmptyHosts () {
const hosts = this.hostsString
.split('\n')
.filter(host => host && host.length !== 0) // Eject empty hosts
return hosts
}
} }

View File

@ -1,5 +1,3 @@
<h3>Following list</h3>
<p-dataTable <p-dataTable
[value]="following" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage" [value]="following" [lazy]="true" [paginator]="true" [totalRecords]="totalRecords" [rows]="rowsPerPage"
sortField="createdAt" (onLazyLoad)="loadLazy($event)" sortField="createdAt" (onLazyLoad)="loadLazy($event)"
@ -10,7 +8,7 @@
<p-column field="createdAt" header="Created date" [sortable]="true"></p-column> <p-column field="createdAt" header="Created date" [sortable]="true"></p-column>
<p-column header="Unfollow" styleClass="action-cell"> <p-column header="Unfollow" styleClass="action-cell">
<ng-template pTemplate="body" let-following="rowData"> <ng-template pTemplate="body" let-following="rowData">
<span (click)="removeFollowing(following)" class="glyphicon glyphicon-remove glyphicon-black" title="Unfollow"></span> <my-delete-button (click)="removeFollowing(following)"></my-delete-button>
</ng-template> </ng-template>
</p-column> </p-column>
</p-dataTable> </p-dataTable>

View File

@ -1,4 +1,6 @@
<div class="follows-menu"> <div class="admin-sub-header">
<div class="admin-sub-title">Manage follows</div>
<tabset #followsMenuTabs> <tabset #followsMenuTabs>
<tab *ngFor="let link of links"> <tab *ngFor="let link of links">
<ng-template tabHeading> <ng-template tabHeading>
@ -8,4 +10,6 @@
</tabset> </tabset>
</div> </div>
<router-outlet></router-outlet> <router-outlet></router-outlet>

View File

@ -1,3 +1,4 @@
.follows-menu { .admin-sub-title {
margin-top: 20px; flex-grow: 0;
margin-right: 30px;
} }

View File

@ -47,7 +47,7 @@ export class FollowsComponent implements OnInit, AfterViewInit {
for (let i = 0; i < this.links.length; i++) { for (let i = 0; i < this.links.length; i++) {
const path = this.links[i].path const path = this.links[i].path
if (url.endsWith(path) === true) { if (url.endsWith(path) === true && this.followsMenuTabs.tabs[i]) {
this.followsMenuTabs.tabs[i].active = true this.followsMenuTabs.tabs[i].active = true
return return
} }

View File

@ -64,5 +64,5 @@
</div> </div>
</div> </div>
<input type="submit" value="{{ getFormButtonTitle() }}" class="btn btn-default" [disabled]="!form.valid"> <input type="submit" value="{{ getFormButtonTitle() }}" [disabled]="!form.valid">
</form> </form>

View File

@ -1,14 +1,8 @@
import { FormControl } from '@angular/forms' export function validateHost (value: string) {
export function validateHost (c: FormControl) {
// Thanks to http://stackoverflow.com/a/106223 // Thanks to http://stackoverflow.com/a/106223
const HOST_REGEXP = new RegExp( const HOST_REGEXP = new RegExp(
'^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$' '^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
) )
return HOST_REGEXP.test(c.value) ? null : { return HOST_REGEXP.test(value)
validateHost: {
valid: false
}
}
} }

View File

@ -59,6 +59,7 @@
text-align: center; text-align: center;
padding: 0 17px 0 13px; padding: 0 17px 0 13px;
cursor: pointer; cursor: pointer;
outline: 0;
} }
@mixin peertube-button-link { @mixin peertube-button-link {

View File

@ -269,21 +269,25 @@ p-datatable {
} }
.nav { .nav {
margin-top: 10px;
font-size: 16px !important; font-size: 16px !important;
border: none !important; border: none !important;
.nav-item .nav-link { .nav-item .nav-link {
height: 30px !important;
margin-right: 30px; margin-right: 30px;
padding: 0 15px; padding: 0;
display: flex;
align-items: center;
border-radius: 3px; border-radius: 3px;
border: none !important; border: none !important;
.tab-link {
display: flex !important;
align-items: center;
height: 30px !important;
padding: 0 15px;
}
&, & a { &, & a {
color: #000 !important; color: #000 !important;
@include disable-default-a-behaviour;
} }
&.active, &:hover { &.active, &:hover {