separate monitors to users

This commit is contained in:
koplenov 2025-08-17 01:32:35 +03:00
parent 94408bcf32
commit fc8d23d326
5 changed files with 217 additions and 129 deletions

70
app/app.view.css.ts Normal file
View file

@ -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,
},
});
}

View file

@ -1,23 +1,42 @@
$hd_canary_app $mol_page $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 / body /
<= List_sites $mol_list rows <= sites / <= Target_list $mol_gallery items <= target_list /
<= New_site_string $mol_string <= Target*0 $mol_list rows <= target_rows* /
hint \https://domain.com <= Target_main* $mol_view sub /
<= Add_site_button $mol_button_minor <= Target_status* $mol_view
title \Добавить сайт sub / <= target_status* \
click <= add_site null <= Target_url* $mol_link
Site* $mol_list rows / title <= target_title* \
<= Domain_labeler* $mol_labeler uri <= target_url* \
title \Сайт: <= Target_remove* $mol_button_minor
content / click <=> target_remove* null
<= Text_1* $mol_paragraph sub / <= Target_remove_icon* $mol_icon_close
title <= status* \ <= Target_message* $mol_view
<= Last_time_labeler* $mol_labeler sub / <= target_message*? \
title \Дата последнего пинга: <= Target_moment* $mol_view
content / sub / <= target_moment*? <= waiting_hint @ \Waiting...
<= Text_2* $mol_paragraph
title <= last_ping_time* \
- <= Delete_site_button* $mol_button_minor
title \Удалить
click <= delete_site* null

View file

@ -4,90 +4,91 @@ namespace $.$$ {
] ]
export class $hd_canary_app extends $.$hd_canary_app { 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 @ $mol_mem
home() { 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! const ref = $hyoo_crus_ref( this.$.$mol_fetch.text( '/ref' ) )
} home.land().give(ref, $hyoo_crus_rank_post("just"))
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()? "🟢" : "🔴"
}
click() { // и заносим это в глобальную базу
// const new_site = new $hd_canary_app_home_site() this.users().dive(this.my_key(), $hyoo_crus_atom_vary, home.ref().description)
// 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()})
} }
console.log({landaaa: this.home().Sites(null)?.land_ref()}) return home
// 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!
})
})
} }
} }
} }

View file

@ -9,7 +9,9 @@ namespace $ {
export class $hd_canary_app_home_site extends $hyoo_crus_dict.with( { export class $hd_canary_app_home_site extends $hyoo_crus_dict.with( {
/** Type of value */ /** 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_time: $hyoo_crus_atom_time,
last_ping_status: $hyoo_crus_atom_bool, last_ping_status: $hyoo_crus_atom_bool,
}) { }) {
@ -19,12 +21,15 @@ namespace $ {
this.$.$mol_state_time.now( 5000 ) this.$.$mol_state_time.now( 5000 )
if(this.can_change()) { console.log(this.land().ref().description)
const domain = this.domain()!.val() as string
// console.log({action:"tick", domain: domain, })//this.last_ping_time()?.val()}) if(this.can_change()) {
const url = this.url()!.val() as string
const request = $mol_fetch.response(domain) 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_status(null)!.val( request.code() == 200)
this.last_ping_time(null)!.val( new $mol_time_moment) this.last_ping_time(null)!.val( new $mol_time_moment)
// console.log({status: request.code()}) // console.log({status: request.code()})

View file

@ -10,43 +10,36 @@ namespace $ {
export class $hd_canary extends $hyoo_crus_app_node { export class $hd_canary extends $hyoo_crus_app_node {
@ $mol_mem @ $mol_mem
_stat_update() { _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()) { for (const ref of list.keys()) {
site.tick() 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 @ $mol_memo.method
sites() { join() {
return new $hd_canary_sites return new $hd_canary_join
} }
} }
export class $hd_canary_join extends $mol_rest_resource {
export class $hd_canary_sites extends $mol_rest_resource {
POST( msg: $mol_rest_message ) { GET( msg: $mol_rest_message ) {
const {domain} = JSON.parse(msg.text()) // const home_land = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ).land()
// home_land.give(null, $hyoo_crus_rank_join("just"))
const home = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ) // msg.reply( home_land.ref().description! )
const new_site = home.Sites(null)!.make({ '': $hyoo_crus_rank_rule })
new_site.domain(null)!.val(domain)
msg.reply( new_site.land().ref().description! )
}
// TODO const home_land = this.$.$hyoo_crus_glob.home( $hd_canary_app_home ).land()
DELETE( msg: $mol_rest_message ): void { const list = home_land.Node( $hyoo_crus_dict ).Item('')
// const {ref} = JSON.parse(msg.text()) list.land().give(null, $hyoo_crus_rank_rule)
msg.reply( list.ref().description! )
// 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" )
} }
} }