protected constructor(name: string, type: RoleType, attributes: T, errors: Errors = new Errors()) { super(); ValidatableMixin.call(this); this.type = stream(type); this.name = stream(name); this.attributes = stream(attributes); this.errors(errors); this.validatePresenceOf("name"); this.validateFormatOf("name", new RegExp("^[-a-zA-Z0-9_][-a-zA-Z0-9_.]*$"), {message: "Invalid Id. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period)."}); this.validateMaxLength("name", 255, {message: "The maximum allowed length is 255 characters."}); }
export default function FollowersCtrl(userId: string): IRelationCtrl { socket.createDefault() const related: Mithril.Stream<Related[]> = stream([]) const paginator: Mithril.Stream<Paginator<Related> | undefined> = stream(undefined) const isLoadingNextPage = stream(false) function loadNextPage(page: number) { isLoadingNextPage(true) xhr.followers(userId, page) .then(data => { isLoadingNextPage(false) paginator(data.paginator) related(related().concat(data.paginator.currentPageResults)) redraw() }) .catch(handleXhrError) redraw() } xhr.followers(userId, 1, true) .then(data => { paginator(data.paginator) related(data.paginator.currentPageResults) redraw() }) .catch(handleXhrError) function setNewUserState(obj: Related, newData: xhr.RelationActionResult) { obj.relation = newData.following redraw() } return { related, loadNextPage, isLoadingNextPage, toggleFollowing: (obj: Related) => { if (obj.relation) xhr.unfollow(obj.user).then(d => setNewUserState(obj, d)) else xhr.follow(obj.user).then(d => setNewUserState(obj, d)) }, challenge(id: string) { challengeForm.open(id) }, paginator } }
constructor(url: string, autoUpdate: boolean, name: string, destination: string, checkExternals: boolean, username: string, password: string, encryptedPassword: string, filter: Filter, invertFilter: boolean, errors: { [key: string]: string[] } = {}) { super(url, autoUpdate, name, destination, filter, invertFilter, errors); this.checkExternals = stream(checkExternals); this.username = stream(username); this.password = stream(plainOrCipherValue({plainText: password, cipherText: encryptedPassword})); }
export default function oninit(userId: string) { const user: Mithril.Stream<UserFullProfile | undefined> = stream(undefined) function setNewUserState(newData: Partial<UserFullProfile>) { Object.assign(user(), newData) redraw() } xhr.user(userId) .then(data => { user(data) redraw() }) .then(session.refresh) .catch(utils.handleXhrError) return { user, isMe: () => session.getUserId() === userId, toggleFollowing() { const u = user() if (u && u.following) xhr.unfollow(u.id).then(setNewUserState) else if (u) xhr.follow(u.id).then(setNewUserState) }, toggleBlocking() { const u = user() if (u && u.blocking) xhr.unblock(u.id).then(setNewUserState) else if (u) xhr.block(u.id).then(setNewUserState) }, goToGames() { const u = user() if (u) { router.set(`/@/${u.id}/games`) } }, goToUserTV() { const u = user() if (u) { router.set(`/@/${u.id}/tv`) } }, challenge() { const u = user() if (u) { challengeForm.open(u.id) } }, composeMessage() { const u = user() if (u) { router.set(`/inbox/new/${u.id}`) } } } }
constructor(url: string, autoUpdate: boolean, name: string, branch: string, destination: string, filter: Filter, invertFilter: boolean, errors: { [key: string]: string[] } = {}) { super(url, autoUpdate, name, destination, filter, invertFilter, errors); this.branch = stream(branch); }
constructor(url: string, autoUpdate: boolean, name: string, destination: string, domain: string, projectPath: string, username: string, password: string, encryptedPassword: string, filter: Filter, invertFilter: boolean, errors: { [key: string]: string[] } = {}) { super(url, autoUpdate, name, destination, filter, invertFilter, errors); this.domain = stream(domain); this.projectPath = stream(projectPath); this.username = stream(username); this.password = stream(plainOrCipherValue({plainText: password, cipherText: encryptedPassword})); this.validatePresenceOf("projectPath"); this.validatePresenceOf("username"); this.validatePresenceOfPassword("password"); }
constructor(url: string, autoUpdate: boolean, name: string, destination: string, port: string, useTickets: boolean, view: string, username: string, password: string, encryptedPassword: string, filter: Filter, invertFilter: boolean, errors: { [key: string]: string[] } = {}) { super(url, autoUpdate, name, destination, filter, invertFilter, errors); this.port = stream(port); this.useTickets = stream(useTickets); this.view = stream(view); this.username = stream(username); this.password = stream(plainOrCipherValue({plainText: password, cipherText: encryptedPassword})); this.validatePresenceOf("view"); this.validatePresenceOf("port", {message: ErrorMessages.mustBePresent("Host and Port")}); }
export default function ImporterCtrl(): IImporterCtrl { const importing = stream(false) function submitOnline(pgn: string, analyse: boolean): Promise<OnlineGameData> { const data: {[i: string]: string } = { pgn } if (analyse) data.analyse = '1' return fetchJSON('/import', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', 'Accept': 'application/vnd.lichess.v' + globalConfig.apiVersion + '+json' }, body: serializeQueryParameters(data) }, true) } window.addEventListener('keyboardDidHide', helper.onKeyboardHide) window.addEventListener('keyboardDidShow', helper.onKeyboardShow) return { importGame(pgn: string) { importing(true) redraw() submitOnline(pgn, settings.importer.analyse()) .then(data => { router.set(`/analyse/online${data.url.round}`) }) .catch(err => { importing(false) redraw() console.error(err) handleXhrError(err) }) }, importing } }
constructor(profiles: ElasticAgentProfile[]) { this.profiles = stream(profiles); }
constructor(variables: Variable[]) { this.variables = stream(variables); }