From fc8d23d3263360486a272a0bf0471eda7b56211f Mon Sep 17 00:00:00 2001 From: koplenov Date: Sun, 17 Aug 2025 01:32:35 +0300 Subject: [PATCH] separate monitors to users --- app/app.view.css.ts | 70 ++++++++++++++++++++ app/app.view.tree | 61 ++++++++++++------ app/app.view.ts | 153 ++++++++++++++++++++++---------------------- app/home/home.ts | 17 +++-- canary.node.tsx | 45 ++++++------- 5 files changed, 217 insertions(+), 129 deletions(-) create mode 100644 app/app.view.css.ts diff --git a/app/app.view.css.ts b/app/app.view.css.ts new file mode 100644 index 0000000..3bfa38b --- /dev/null +++ b/app/app.view.css.ts @@ -0,0 +1,70 @@ +namespace $.$$ { + $mol_style_define($.$hd_canary_app, { + Add: { + flex: { + shrink: 1, + }, + }, + Body_content: { + gap: $mol_gap.block, + }, + Target: { + margin: $mol_gap.block, + padding: $mol_gap.block, + flex: { + basis: `15rem`, + grow: 1, + }, + background: { + color: $mol_theme.card, + }, + border: { + radius: $mol_gap.round, + }, + box: { + shadow: [{ + x: 0, + y: 0, + blur: 0, + spread: `1px`, + color: $mol_theme.line, + }], + }, + }, + Target_main: { + align: { + items: 'flex-start', + }, + }, + Status_total: { + width: `2.5rem`, + height: `2.5rem`, + padding: `.5rem`, + justify: { + content: 'center', + }, + }, + Target_status: { + width: `2.5rem`, + height: `2.5rem`, + padding: `.5rem`, + justify: { + content: 'center', + }, + }, + Target_url: { + flex: { + grow: 1, + shrink: 1, + }, + }, + Target_moment: { + padding: $mol_gap.text, + color: $mol_theme.shade, + }, + Target_message: { + padding: $mol_gap.text, + color: $mol_theme.focus, + }, + }); +} diff --git a/app/app.view.tree b/app/app.view.tree index eb92f5b..9e147f3 100644 --- a/app/app.view.tree +++ b/app/app.view.tree @@ -1,23 +1,42 @@ $hd_canary_app $mol_page - title \Hyper Canary + title @ \Hyper Canary + targets? * + target_result*? 1 + plugins / + <= Theme $mol_theme_auto + head / + <= Status_total $mol_chip title <= status_total \ + <= Title + <= Add $mol_view sub / + <= Add_url $mol_string + hint @ \URL + value? <=> add_url? \ + submit? <=> add_submit? null + <= Add_title $mol_string + hint @ \Title + value? <=> add_title? \ + submit? <=> add_submit? null + <= Add_submit $mol_button_minor + hint @ \Add + click? <=> add_submit? null + sub / + <= Add_submit_icon $mol_icon_plus + <= Tools + tools / + <= Lights $mol_lights_toggle body / - <= List_sites $mol_list rows <= sites / - <= New_site_string $mol_string - hint \https://domain.com - <= Add_site_button $mol_button_minor - title \Добавить сайт - click <= add_site null - Site* $mol_list rows / - <= Domain_labeler* $mol_labeler - title \Сайт: - content / - <= Text_1* $mol_paragraph - title <= status* \ - <= Last_time_labeler* $mol_labeler - title \Дата последнего пинга: - content / - <= Text_2* $mol_paragraph - title <= last_ping_time* \ - - <= Delete_site_button* $mol_button_minor - title \Удалить - click <= delete_site* null + <= Target_list $mol_gallery items <= target_list / + <= Target*0 $mol_list rows <= target_rows* / + <= Target_main* $mol_view sub / + <= Target_status* $mol_view + sub / <= target_status* \ + <= Target_url* $mol_link + title <= target_title* \ + uri <= target_url* \ + <= Target_remove* $mol_button_minor + click <=> target_remove* null + sub / <= Target_remove_icon* $mol_icon_close + <= Target_message* $mol_view + sub / <= target_message*? \ + <= Target_moment* $mol_view + sub / <= target_moment*? <= waiting_hint @ \Waiting... diff --git a/app/app.view.ts b/app/app.view.ts index 951f6b7..8df8507 100644 --- a/app/app.view.ts +++ b/app/app.view.ts @@ -4,90 +4,91 @@ namespace $.$$ { ] export class $hd_canary_app extends $.$hd_canary_app { - + + status_total() { + return this.home().Sites(null)!.remote_list().every( key => key.last_ping_status()?.val() == true) ? "🟢" : "🔴" + } + + target_status( prop: $hd_canary_app_home_site ) { + return prop.last_ping_status()?.val() ? "🟢" : "🔴" + } + target_title(prop: $hd_canary_app_home_site) { + return prop.title()!.val() as string + } + target_url(prop: $hd_canary_app_home_site) { + return prop.url()!.val() as string; + } + target_moment(prop: $hd_canary_app_home_site) { + return ((prop.last_ping_time()?.val() as $mol_time_moment) ?? "planed ping").toString('YYYY-MM-DD hh:mm:ss')// ?? prop.ref().description! as any + } + + target_list() { + return this.home().Sites(null)!.remote_list().map( key => this.Target( key ) ) ?? [] + } + + is_valid_http_url(string: string) { + let url; + try { + url = new URL(string); + } catch (_) { + return false; + } + return url.protocol === "http:" || url.protocol === "https:"; + } + + add_submit() { + const url = this.add_url().trim() + if (url == "") throw "Empty url!" + + if (this.is_valid_http_url(url) == false) throw "Not valid url!" + + + let title = this.add_title().trim() + if (title == "") title = url.replace(/(^https?:\/\/)|(\/+$)/g, ''); + + const new_site = this.home().Sites(null)!.make({ '': $hyoo_crus_rank_rule }) + new_site.url(null)!.val(url) + new_site.title(null)!.val(title) + + this.add_url(''); + this.add_title(''); + } + + target_remove(prop: $hd_canary_app_home_site) { + const current = this.home().Sites(null)!.items_vary() + const new_list = current.filter(item => item != prop.ref()) + this.home().Sites(null)!.items_vary(new_list) + } + + // наш id клиента + my_key() { + return this.$.$hyoo_crus_auth.current().lord().description! + } + + @ $mol_mem + users() { + const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/join' ) ) + return this.$.$hyoo_crus_glob.Node( ref, $hyoo_crus_dict ) + } + @ $mol_mem home() { - const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/ref' ) ) - return this.$.$hyoo_crus_glob.Node( ref, $hd_canary_app_home ) - } + // берем свой уголок + const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ) - sites() { - return this.home().Sites(null)!.remote_list().map( key => this.Site( key ) ) ?? [] - } - status( prop: $hd_canary_app_home_site ) { - return this.last_ping_status(prop) + " " + this.domain(prop) - } + // проверяем есть ли он в базе + if (this.users().has(this.my_key()) == false) { - domain( prop: $hd_canary_app_home_site ) { - return prop.domain()!.val() ?? prop.ref().description! - } - last_ping_time( prop: $hd_canary_app_home_site ) { - return prop.last_ping_time()!.val() ?? prop.ref().description! as any - } - last_ping_status( prop: $hd_canary_app_home_site ) { - return prop.last_ping_status()!.val()? "🟢" : "🔴" - } + // даем серверу права на запись + const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/ref' ) ) + home.land().give(ref, $hyoo_crus_rank_post("just")) - click() { - // const new_site = new $hd_canary_app_home_site() - // new_site.domain("some_value") - - // const site = this.home().land().Node( $hd_canary_app_home_site ).Item('') - // console.log( site ) - - // console.log( this.home().can_change()) - - // const new_site = this.home().Sites(null)!.make({ '': $hyoo_crus_rank_read }) - // new_site.domain("test") - - for (const site of this.home().Sites(null)!.remote_list()) { - console.log({site}) - console.log({domain: site.domain()?.val()}) + // и заносим это в глобальную базу + this.users().dive(this.my_key(), $hyoo_crus_atom_vary, home.ref().description) } - console.log({landaaa: this.home().Sites(null)?.land_ref()}) - - - // console.log( - // this.home().Sites(null)!.remote_list() - // ) - - - // const masters = this.$.$hyoo_crus_glob.yard().masters()//$mol_wire_sync( this.$.$hyoo_crus_glob.yard() ).masters() - // this.Port_masters( null )!.tick_instant( masters ) // pct - // console.log( {masters} ) - } - - add_site() { - const domain = this.New_site_string().value() - - // const new_site = this.home().Sites(null)!.make({ '': $hyoo_crus_rank_rule }) - // new_site.domain(null)!.val(domain) - - $mol_fetch.response("/sites", { - method: "POST", - headers: { - 'Content-Type': 'application/json;charset=utf-8' - }, - body: JSON.stringify({ - domain - }) - }) - } - - delete_site( prop: $hd_canary_app_home_site ) { - - $mol_fetch.response("/sites", { - method: "DELETE", - headers: { - 'Content-Type': 'application/json;charset=utf-8' - }, - body: JSON.stringify({ - ref: prop.ref().description! - }) - }) - + return home } } } diff --git a/app/home/home.ts b/app/home/home.ts index 1608393..4b140b0 100644 --- a/app/home/home.ts +++ b/app/home/home.ts @@ -9,7 +9,9 @@ namespace $ { export class $hd_canary_app_home_site extends $hyoo_crus_dict.with( { /** Type of value */ - domain: $hyoo_crus_atom_str, + url: $hyoo_crus_atom_str, + title: $hyoo_crus_atom_str, + last_ping_time: $hyoo_crus_atom_time, last_ping_status: $hyoo_crus_atom_bool, }) { @@ -19,12 +21,15 @@ namespace $ { this.$.$mol_state_time.now( 5000 ) - if(this.can_change()) { - const domain = this.domain()!.val() as string + console.log(this.land().ref().description) - // console.log({action:"tick", domain: domain, })//this.last_ping_time()?.val()}) - - const request = $mol_fetch.response(domain) + if(this.can_change()) { + const url = this.url()!.val() as string + const title = this.title()!.val() as string + + console.log({action:"tick", url, title }) + + const request = $mol_fetch.response(url) this.last_ping_status(null)!.val( request.code() == 200) this.last_ping_time(null)!.val( new $mol_time_moment) // console.log({status: request.code()}) diff --git a/canary.node.tsx b/canary.node.tsx index 500c681..e97446a 100644 --- a/canary.node.tsx +++ b/canary.node.tsx @@ -10,43 +10,36 @@ namespace $ { export class $hd_canary extends $hyoo_crus_app_node { @ $mol_mem _stat_update() { - const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ) + const home_land = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ).land() + const list = home_land.Node( $hyoo_crus_dict ).Item('') - for (const site of home.Sites(null)!.remote_list()) { - site.tick() + for (const ref of list.keys()) { + const user = this.$.$hyoo_crus_glob.Node( $hyoo_crus_ref( ref as string ), $hd_canary_app_home ) + + for (const site of user.Sites(null)!.remote_list()) { + site.tick() + } } } @ $mol_memo.method - sites() { - return new $hd_canary_sites + join() { + return new $hd_canary_join } } - - export class $hd_canary_sites extends $mol_rest_resource { + export class $hd_canary_join extends $mol_rest_resource { - POST( msg: $mol_rest_message ) { - const {domain} = JSON.parse(msg.text()) - - const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ) - const new_site = home.Sites(null)!.make({ '': $hyoo_crus_rank_rule }) - new_site.domain(null)!.val(domain) - - msg.reply( new_site.land().ref().description! ) - } + GET( msg: $mol_rest_message ) { + // const home_land = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ).land() + // home_land.give(null, $hyoo_crus_rank_join("just")) + // msg.reply( home_land.ref().description! ) - // TODO - DELETE( msg: $mol_rest_message ): void { - // const {ref} = JSON.parse(msg.text()) - - // const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ) - // const current_all = home.Sites(null)!.items_vary() - // console.log({current_all}) - // const new_all = current_all.filter(item => item?.toString() != ref) - // home.Sites(null)!.splice(new_all) - // msg.reply( "ok" ) + const home_land = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ).land() + const list = home_land.Node( $hyoo_crus_dict ).Item('') + list.land().give(null, $hyoo_crus_rank_rule) + msg.reply( list.ref().description! ) } }