From 88f17eab0281ee8ceb94ac253fe24a39ea03aa20 Mon Sep 17 00:00:00 2001 From: plazmoid Date: Sun, 27 Mar 2022 17:31:42 +0500 Subject: [PATCH] added web frontend --- .cargo/config.toml | 6 +- .gitignore | 1 + Cargo.toml | 5 +- Makefile.toml | 10 +- bin/u_agent/Cargo.toml | 2 +- bin/u_panel/Cargo.toml | 4 +- bin/u_panel/be/Cargo.toml | 10 -- bin/u_panel/be/src/lib.rs | 23 ---- bin/u_panel/fe/Cargo.toml | 12 -- bin/u_panel/fe/index.html | 9 -- bin/u_panel/fe/src/main.rs | 51 -------- bin/u_panel/src/argparse.rs | 4 +- bin/u_panel/src/main.rs | 1 + bin/u_panel/src/server/fe/README.md | 27 +++++ bin/u_panel/src/server/fe/angular.json | 111 ++++++++++++++++++ bin/u_panel/src/server/fe/karma.conf.js | 44 +++++++ bin/u_panel/src/server/fe/package.json | 39 ++++++ .../server/fe/src/app/app-routing.module.ts | 10 ++ .../src/server/fe/src/app/app.component.html | 1 + .../src/server/fe/src/app/app.component.less | 0 .../server/fe/src/app/app.component.spec.ts | 35 ++++++ .../src/server/fe/src/app/app.component.ts | 10 ++ .../src/server/fe/src/app/app.module.ts | 18 +++ .../fe/src/environments/environment.prod.ts | 3 + .../server/fe/src/environments/environment.ts | 16 +++ bin/u_panel/src/server/fe/src/favicon.ico | Bin 0 -> 948 bytes bin/u_panel/src/server/fe/src/index.html | 13 ++ bin/u_panel/src/server/fe/src/main.ts | 12 ++ bin/u_panel/src/server/fe/src/polyfills.ts | 53 +++++++++ bin/u_panel/src/server/fe/src/styles.less | 1 + bin/u_panel/src/server/fe/src/test.ts | 26 ++++ bin/u_panel/src/server/fe/tsconfig.app.json | 15 +++ bin/u_panel/src/server/fe/tsconfig.json | 32 +++++ bin/u_panel/src/server/fe/tsconfig.spec.json | 18 +++ bin/u_panel/src/server/mod.rs | 56 +++++++++ bin/u_server/Cargo.toml | 2 +- lib/u_lib/src/errors/variants.rs | 4 +- 37 files changed, 567 insertions(+), 117 deletions(-) delete mode 100644 bin/u_panel/be/Cargo.toml delete mode 100644 bin/u_panel/be/src/lib.rs delete mode 100644 bin/u_panel/fe/Cargo.toml delete mode 100644 bin/u_panel/fe/index.html delete mode 100644 bin/u_panel/fe/src/main.rs create mode 100644 bin/u_panel/src/server/fe/README.md create mode 100644 bin/u_panel/src/server/fe/angular.json create mode 100644 bin/u_panel/src/server/fe/karma.conf.js create mode 100644 bin/u_panel/src/server/fe/package.json create mode 100644 bin/u_panel/src/server/fe/src/app/app-routing.module.ts create mode 100644 bin/u_panel/src/server/fe/src/app/app.component.html create mode 100644 bin/u_panel/src/server/fe/src/app/app.component.less create mode 100644 bin/u_panel/src/server/fe/src/app/app.component.spec.ts create mode 100644 bin/u_panel/src/server/fe/src/app/app.component.ts create mode 100644 bin/u_panel/src/server/fe/src/app/app.module.ts create mode 100644 bin/u_panel/src/server/fe/src/environments/environment.prod.ts create mode 100644 bin/u_panel/src/server/fe/src/environments/environment.ts create mode 100644 bin/u_panel/src/server/fe/src/favicon.ico create mode 100644 bin/u_panel/src/server/fe/src/index.html create mode 100644 bin/u_panel/src/server/fe/src/main.ts create mode 100644 bin/u_panel/src/server/fe/src/polyfills.ts create mode 100644 bin/u_panel/src/server/fe/src/styles.less create mode 100644 bin/u_panel/src/server/fe/src/test.ts create mode 100644 bin/u_panel/src/server/fe/tsconfig.app.json create mode 100644 bin/u_panel/src/server/fe/tsconfig.json create mode 100644 bin/u_panel/src/server/fe/tsconfig.spec.json create mode 100644 bin/u_panel/src/server/mod.rs diff --git a/.cargo/config.toml b/.cargo/config.toml index 21748f1..433fea9 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,6 @@ [build] -rustflags = ["-L", "/home/ortem/src/rust/unki/static/lib"] \ No newline at end of file +rustflags = [ + "-L", "/home/ortem/src/rust/unki/static/lib", + "--remap-path-prefix=/home/ortem/src/rust/unki=src", + "--remap-path-prefix=/home/ortem/.cargo=cargo" +] diff --git a/.gitignore b/.gitignore index 3b8e7ff..fd55330 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ certs/ static/ .vscode/ release/ +**/node_modules/ **/*.rs.bk **/*.pyc diff --git a/Cargo.toml b/Cargo.toml index c22386b..a9f8f02 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,6 @@ members = [ "bin/u_agent", "bin/u_panel", - #"bin/u_panel/be", - #"bin/u_panel/fe", "bin/u_run", "bin/u_server", "lib/u_lib", @@ -13,7 +11,8 @@ members = [ [profile.release] panic = "abort" +strip = "symbols" [profile.dev] debug = true # Добавляет флаг `-g` для компилятора; -opt-level = 0 \ No newline at end of file +opt-level = 0 diff --git a/Makefile.toml b/Makefile.toml index 45c2842..4c11b71 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -13,12 +13,18 @@ OPENSSL_DIR = "${PREFIX}" [tasks.build_static_libs] script = "./scripts/build_musl_libs.sh" +[tasks.build_frontend] +script = ''' +cd ./bin/u_panel/src/server/fe +ng build +''' + [tasks.clean] command = "${CARGO}" args = ["clean"] [tasks.cargo_build] -dependencies = ["build_static_libs"] +dependencies = ["build_static_libs", "build_frontend"] command = "${CARGO}" args = ["build", "--target", "${TARGET}", "${@}"] @@ -39,7 +45,7 @@ args = [] [tasks.run] script = ''' -echo "Only integration tests are supported." +echo "wtf are you running? run binaries dud!" exit 1 ''' diff --git a/bin/u_agent/Cargo.toml b/bin/u_agent/Cargo.toml index 3f7a884..500fdb0 100644 --- a/bin/u_agent/Cargo.toml +++ b/bin/u_agent/Cargo.toml @@ -17,4 +17,4 @@ openssl = "*" u_lib = { version = "*", path = "../../lib/u_lib" } [build-dependencies] -openssl = "*" \ No newline at end of file +openssl = "*" diff --git a/bin/u_panel/Cargo.toml b/bin/u_panel/Cargo.toml index 4fb5761..2bccf84 100644 --- a/bin/u_panel/Cargo.toml +++ b/bin/u_panel/Cargo.toml @@ -7,6 +7,7 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "3.3.2" backtrace = "0.3.61" structopt = "0.3.21" log = "^0.4" @@ -15,7 +16,6 @@ uuid = "0.6.5" serde_json = "1.0.4" serde = { version = "1.0.114", features = ["derive"] } tokio = { version = "1.11.0", features = ["rt", "rt-multi-thread"] } -# be = { version = "*", path = "./be" } u_lib = { version = "*", path = "../../lib/u_lib" } tui = { version = "0.16", default-features = false, features = ['crossterm'] } crossterm = "0.22.1" @@ -29,3 +29,5 @@ tracing = "0.1.29" tracing-subscriber = { version = "0.3.3", features = ["env-filter"]} signal-hook = "0.3.12" tracing-appender = "0.2.0" +rust-embed = { version = "6.3.0", features = ["debug-embed", "compression"] } +mime_guess = "2.0.4" diff --git a/bin/u_panel/be/Cargo.toml b/bin/u_panel/be/Cargo.toml deleted file mode 100644 index 8831379..0000000 --- a/bin/u_panel/be/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "be" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -actix-web = "3.3.2" -u_lib = { version = "*", path = "../../../lib/u_lib" } \ No newline at end of file diff --git a/bin/u_panel/be/src/lib.rs b/bin/u_panel/be/src/lib.rs deleted file mode 100644 index d7c5117..0000000 --- a/bin/u_panel/be/src/lib.rs +++ /dev/null @@ -1,23 +0,0 @@ -/* -Tabs: Agents, Tasks, Summary -every tab has list page and item page with more info/actions - -Agents: - -| id | alias | ..see struct | tasks done -| stripped | alias | ... | clickable number of assigned jobs - -almost all fields are editable, rows are deletable - - -*/ - -use actix_web::{web, App, HttpResponse, HttpServer}; - -#[actix_web::main] -pub async fn serve() -> std::io::Result<()> { - let addr = "127.0.0.1:8080"; - let app = || App::new().route("/", web::get().to(|| HttpResponse::Ok().body("ok"))); - println!("Serving at http://{}", addr); - HttpServer::new(app).bind(addr)?.run().await -} diff --git a/bin/u_panel/fe/Cargo.toml b/bin/u_panel/fe/Cargo.toml deleted file mode 100644 index f84fa64..0000000 --- a/bin/u_panel/fe/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "fe" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -u_lib = { version = "*", path = "../../../lib/u_lib" } -wasm-bindgen = "0.2.78" -yew = "0.18.0" -yew-router = "0.15.0" diff --git a/bin/u_panel/fe/index.html b/bin/u_panel/fe/index.html deleted file mode 100644 index de24c98..0000000 --- a/bin/u_panel/fe/index.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - Yew App - - - \ No newline at end of file diff --git a/bin/u_panel/fe/src/main.rs b/bin/u_panel/fe/src/main.rs deleted file mode 100644 index c7e8f03..0000000 --- a/bin/u_panel/fe/src/main.rs +++ /dev/null @@ -1,51 +0,0 @@ -use wasm_bindgen::prelude::*; -use yew::prelude::*; -enum Msg { - AddOne, -} -struct Model { - // `ComponentLink` is like a reference to a component. - // It can be used to send messages to the component - link: ComponentLink, - value: i64, -} - -impl Component for Model { - type Message = Msg; - type Properties = (); - - fn create(_props: Self::Properties, link: ComponentLink) -> Self { - Self { link, value: 0 } - } - - fn update(&mut self, msg: Self::Message) -> ShouldRender { - match msg { - Msg::AddOne => { - self.value += 1; - // the value has changed so we need to - // re-render for it to appear on the page - true - } - } - } - - fn change(&mut self, _props: Self::Properties) -> ShouldRender { - // Should only return "true" if new properties are different to - // previously received properties. - // This component has no properties so we will always return "false". - false - } - - fn view(&self) -> Html { - html! { -
- -

{ self.value }

-
- } - } -} - -pub fn main() { - yew::start_app::(); -} diff --git a/bin/u_panel/src/argparse.rs b/bin/u_panel/src/argparse.rs index 651e50d..879ccbb 100644 --- a/bin/u_panel/src/argparse.rs +++ b/bin/u_panel/src/argparse.rs @@ -18,6 +18,7 @@ enum Cmd { Jobs(JobALD), Map(JobMapALD), TUI(TUIArgs), + Serve, } #[derive(StructOpt, Debug)] @@ -134,7 +135,8 @@ pub async fn process_cmd(args: Args) -> UResult<()> { }, Cmd::TUI(args) => crate::tui::init_tui(&args) .await - .map_err(|e| UError::TUIError(e.to_string()))?, + .map_err(|e| UError::PanelError(e.to_string()))?, + Cmd::Serve => crate::server::serve().map_err(|e| UError::PanelError(e.to_string()))?, } Ok(()) } diff --git a/bin/u_panel/src/main.rs b/bin/u_panel/src/main.rs index 63e9e06..d4ba19a 100644 --- a/bin/u_panel/src/main.rs +++ b/bin/u_panel/src/main.rs @@ -1,5 +1,6 @@ mod argparse; mod tui; +mod server; #[macro_use] extern crate async_trait; diff --git a/bin/u_panel/src/server/fe/README.md b/bin/u_panel/src/server/fe/README.md new file mode 100644 index 0000000..d16d556 --- /dev/null +++ b/bin/u_panel/src/server/fe/README.md @@ -0,0 +1,27 @@ +# Fe + +This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.1.2. + +## Development server + +Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. + +## Code scaffolding + +Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. + +## Build + +Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Running unit tests + +Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Running end-to-end tests + +Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. diff --git a/bin/u_panel/src/server/fe/angular.json b/bin/u_panel/src/server/fe/angular.json new file mode 100644 index 0000000..5bb4463 --- /dev/null +++ b/bin/u_panel/src/server/fe/angular.json @@ -0,0 +1,111 @@ +{ + "$schema": "./node_modules/@angular/cli/lib/config/schema.json", + "version": 1, + "newProjectRoot": "projects", + "projects": { + "fe": { + "projectType": "application", + "schematics": { + "@schematics/angular:component": { + "style": "less" + }, + "@schematics/angular:application": { + "strict": true + } + }, + "root": "", + "sourceRoot": "src", + "prefix": "app", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist/fe", + "index": "src/index.html", + "main": "src/main.ts", + "polyfills": "src/polyfills.ts", + "tsConfig": "tsconfig.app.json", + "inlineStyleLanguage": "less", + "assets": [ + "src/favicon.ico", + "src/assets" + ], + "styles": [ + "src/styles.less" + ], + "scripts": [] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "fileReplacements": [ + { + "replace": "src/environments/environment.ts", + "with": "src/environments/environment.prod.ts" + } + ], + "outputHashing": "all" + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "browserTarget": "fe:build:production" + }, + "development": { + "browserTarget": "fe:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "fe:build" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "src/test.ts", + "polyfills": "src/polyfills.ts", + "tsConfig": "tsconfig.spec.json", + "karmaConfig": "karma.conf.js", + "inlineStyleLanguage": "less", + "assets": [ + "src/favicon.ico", + "src/assets" + ], + "styles": [ + "src/styles.less" + ], + "scripts": [] + } + } + } + } + }, + "defaultProject": "fe" +} diff --git a/bin/u_panel/src/server/fe/karma.conf.js b/bin/u_panel/src/server/fe/karma.conf.js new file mode 100644 index 0000000..07a1538 --- /dev/null +++ b/bin/u_panel/src/server/fe/karma.conf.js @@ -0,0 +1,44 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + jasmine: { + // you can add configuration options for Jasmine here + // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html + // for example, you can disable the random execution with `random: false` + // or set a specific seed with `seed: 4321` + }, + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + jasmineHtmlReporter: { + suppressAll: true // removes the duplicated traces + }, + coverageReporter: { + dir: require('path').join(__dirname, './coverage/fe'), + subdir: '.', + reporters: [ + { type: 'html' }, + { type: 'text-summary' } + ] + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/bin/u_panel/src/server/fe/package.json b/bin/u_panel/src/server/fe/package.json new file mode 100644 index 0000000..ae1f9de --- /dev/null +++ b/bin/u_panel/src/server/fe/package.json @@ -0,0 +1,39 @@ +{ + "name": "fe", + "version": "0.0.0", + "scripts": { + "ng": "ng", + "start": "ng serve", + "build": "ng build", + "watch": "ng build --watch --configuration development", + "test": "ng test" + }, + "private": true, + "dependencies": { + "@angular/animations": "~13.1.0", + "@angular/common": "~13.1.0", + "@angular/compiler": "~13.1.0", + "@angular/core": "~13.1.0", + "@angular/forms": "~13.1.0", + "@angular/platform-browser": "~13.1.0", + "@angular/platform-browser-dynamic": "~13.1.0", + "@angular/router": "~13.1.0", + "rxjs": "~7.4.0", + "tslib": "^2.3.0", + "zone.js": "~0.11.4" + }, + "devDependencies": { + "@angular-devkit/build-angular": "~13.1.2", + "@angular/cli": "~13.1.2", + "@angular/compiler-cli": "~13.1.0", + "@types/jasmine": "~3.10.0", + "@types/node": "^12.11.1", + "jasmine-core": "~3.10.0", + "karma": "~6.3.0", + "karma-chrome-launcher": "~3.1.0", + "karma-coverage": "~2.1.0", + "karma-jasmine": "~4.0.0", + "karma-jasmine-html-reporter": "~1.7.0", + "typescript": "~4.5.2" + } +} diff --git a/bin/u_panel/src/server/fe/src/app/app-routing.module.ts b/bin/u_panel/src/server/fe/src/app/app-routing.module.ts new file mode 100644 index 0000000..0297262 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/app/app-routing.module.ts @@ -0,0 +1,10 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; + +const routes: Routes = []; + +@NgModule({ + imports: [RouterModule.forRoot(routes)], + exports: [RouterModule] +}) +export class AppRoutingModule { } diff --git a/bin/u_panel/src/server/fe/src/app/app.component.html b/bin/u_panel/src/server/fe/src/app/app.component.html new file mode 100644 index 0000000..171ac03 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/app/app.component.html @@ -0,0 +1 @@ +{{ title }} \ No newline at end of file diff --git a/bin/u_panel/src/server/fe/src/app/app.component.less b/bin/u_panel/src/server/fe/src/app/app.component.less new file mode 100644 index 0000000..e69de29 diff --git a/bin/u_panel/src/server/fe/src/app/app.component.spec.ts b/bin/u_panel/src/server/fe/src/app/app.component.spec.ts new file mode 100644 index 0000000..d2ec0e1 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/app/app.component.spec.ts @@ -0,0 +1,35 @@ +import { TestBed } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; +import { AppComponent } from './app.component'; + +describe('AppComponent', () => { + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [ + RouterTestingModule + ], + declarations: [ + AppComponent + ], + }).compileComponents(); + }); + + it('should create the app', () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app).toBeTruthy(); + }); + + it(`should have as title 'fe'`, () => { + const fixture = TestBed.createComponent(AppComponent); + const app = fixture.componentInstance; + expect(app.title).toEqual('fe'); + }); + + it('should render title', () => { + const fixture = TestBed.createComponent(AppComponent); + fixture.detectChanges(); + const compiled = fixture.nativeElement as HTMLElement; + expect(compiled.querySelector('.content span')?.textContent).toContain('fe app is running!'); + }); +}); diff --git a/bin/u_panel/src/server/fe/src/app/app.component.ts b/bin/u_panel/src/server/fe/src/app/app.component.ts new file mode 100644 index 0000000..25a2bce --- /dev/null +++ b/bin/u_panel/src/server/fe/src/app/app.component.ts @@ -0,0 +1,10 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.less'] +}) +export class AppComponent { + title = 'ты лох'; +} diff --git a/bin/u_panel/src/server/fe/src/app/app.module.ts b/bin/u_panel/src/server/fe/src/app/app.module.ts new file mode 100644 index 0000000..b1c6c96 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/app/app.module.ts @@ -0,0 +1,18 @@ +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { AppRoutingModule } from './app-routing.module'; +import { AppComponent } from './app.component'; + +@NgModule({ + declarations: [ + AppComponent + ], + imports: [ + BrowserModule, + AppRoutingModule + ], + providers: [], + bootstrap: [AppComponent] +}) +export class AppModule { } diff --git a/bin/u_panel/src/server/fe/src/environments/environment.prod.ts b/bin/u_panel/src/server/fe/src/environments/environment.prod.ts new file mode 100644 index 0000000..3612073 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/environments/environment.prod.ts @@ -0,0 +1,3 @@ +export const environment = { + production: true +}; diff --git a/bin/u_panel/src/server/fe/src/environments/environment.ts b/bin/u_panel/src/server/fe/src/environments/environment.ts new file mode 100644 index 0000000..f56ff47 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/environments/environment.ts @@ -0,0 +1,16 @@ +// This file can be replaced during build by using the `fileReplacements` array. +// `ng build` replaces `environment.ts` with `environment.prod.ts`. +// The list of file replacements can be found in `angular.json`. + +export const environment = { + production: false +}; + +/* + * For easier debugging in development mode, you can import the following file + * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. + * + * This import should be commented out in production mode because it will have a negative impact + * on performance if an error is thrown. + */ +// import 'zone.js/plugins/zone-error'; // Included with Angular CLI. diff --git a/bin/u_panel/src/server/fe/src/favicon.ico b/bin/u_panel/src/server/fe/src/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..997406ad22c29aae95893fb3d666c30258a09537 GIT binary patch literal 948 zcmV;l155mgP)CBYU7IjCFmI-B}4sMJt3^s9NVg!P0 z6hDQy(L`XWMkB@zOLgN$4KYz;j0zZxq9KKdpZE#5@k0crP^5f9KO};h)ZDQ%ybhht z%t9#h|nu0K(bJ ztIkhEr!*UyrZWQ1k2+YkGqDi8Z<|mIN&$kzpKl{cNP=OQzXHz>vn+c)F)zO|Bou>E z2|-d_=qY#Y+yOu1a}XI?cU}%04)zz%anD(XZC{#~WreV!a$7k2Ug`?&CUEc0EtrkZ zL49MB)h!_K{H(*l_93D5tO0;BUnvYlo+;yss%n^&qjt6fZOa+}+FDO(~2>G z2dx@=JZ?DHP^;b7*Y1as5^uphBsh*s*z&MBd?e@I>-9kU>63PjP&^#5YTOb&x^6Cf z?674rmSHB5Fk!{Gv7rv!?qX#ei_L(XtwVqLX3L}$MI|kJ*w(rhx~tc&L&xP#?cQow zX_|gx$wMr3pRZIIr_;;O|8fAjd;1`nOeu5K(pCu7>^3E&D2OBBq?sYa(%S?GwG&_0-s%_v$L@R!5H_fc)lOb9ZoOO#p`Nn`KU z3LTTBtjwo`7(HA6 z7gmO$yTR!5L>Bsg!X8616{JUngg_@&85%>W=mChTR;x4`P=?PJ~oPuy5 zU-L`C@_!34D21{fD~Y8NVnR3t;aqZI3fIhmgmx}$oc-dKDC6Ap$Gy>a!`A*x2L1v0 WcZ@i?LyX}70000 + + + + Fe + + + + + + + + diff --git a/bin/u_panel/src/server/fe/src/main.ts b/bin/u_panel/src/server/fe/src/main.ts new file mode 100644 index 0000000..c7b673c --- /dev/null +++ b/bin/u_panel/src/server/fe/src/main.ts @@ -0,0 +1,12 @@ +import { enableProdMode } from '@angular/core'; +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; + +import { AppModule } from './app/app.module'; +import { environment } from './environments/environment'; + +if (environment.production) { + enableProdMode(); +} + +platformBrowserDynamic().bootstrapModule(AppModule) + .catch(err => console.error(err)); diff --git a/bin/u_panel/src/server/fe/src/polyfills.ts b/bin/u_panel/src/server/fe/src/polyfills.ts new file mode 100644 index 0000000..429bb9e --- /dev/null +++ b/bin/u_panel/src/server/fe/src/polyfills.ts @@ -0,0 +1,53 @@ +/** + * This file includes polyfills needed by Angular and is loaded before the app. + * You can add your own extra polyfills to this file. + * + * This file is divided into 2 sections: + * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. + * 2. Application imports. Files imported after ZoneJS that should be loaded before your main + * file. + * + * The current setup is for so-called "evergreen" browsers; the last versions of browsers that + * automatically update themselves. This includes recent versions of Safari, Chrome (including + * Opera), Edge on the desktop, and iOS and Chrome on mobile. + * + * Learn more in https://angular.io/guide/browser-support + */ + +/*************************************************************************************************** + * BROWSER POLYFILLS + */ + +/** + * By default, zone.js will patch all possible macroTask and DomEvents + * user can disable parts of macroTask/DomEvents patch by setting following flags + * because those flags need to be set before `zone.js` being loaded, and webpack + * will put import in the top of bundle, so user need to create a separate file + * in this directory (for example: zone-flags.ts), and put the following flags + * into that file, and then add the following code before importing zone.js. + * import './zone-flags'; + * + * The flags allowed in zone-flags.ts are listed here. + * + * The following flags will work for all browsers. + * + * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame + * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick + * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames + * + * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js + * with the following flag, it will bypass `zone.js` patch for IE/Edge + * + * (window as any).__Zone_enable_cross_context_check = true; + * + */ + +/*************************************************************************************************** + * Zone JS is required by default for Angular itself. + */ +import 'zone.js'; // Included with Angular CLI. + + +/*************************************************************************************************** + * APPLICATION IMPORTS + */ diff --git a/bin/u_panel/src/server/fe/src/styles.less b/bin/u_panel/src/server/fe/src/styles.less new file mode 100644 index 0000000..90d4ee0 --- /dev/null +++ b/bin/u_panel/src/server/fe/src/styles.less @@ -0,0 +1 @@ +/* You can add global styles to this file, and also import other style files */ diff --git a/bin/u_panel/src/server/fe/src/test.ts b/bin/u_panel/src/server/fe/src/test.ts new file mode 100644 index 0000000..00025da --- /dev/null +++ b/bin/u_panel/src/server/fe/src/test.ts @@ -0,0 +1,26 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: { + context(path: string, deep?: boolean, filter?: RegExp): { + (id: string): T; + keys(): string[]; + }; +}; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting(), +); + +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/bin/u_panel/src/server/fe/tsconfig.app.json b/bin/u_panel/src/server/fe/tsconfig.app.json new file mode 100644 index 0000000..82d91dc --- /dev/null +++ b/bin/u_panel/src/server/fe/tsconfig.app.json @@ -0,0 +1,15 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./out-tsc/app", + "types": [] + }, + "files": [ + "src/main.ts", + "src/polyfills.ts" + ], + "include": [ + "src/**/*.d.ts" + ] +} diff --git a/bin/u_panel/src/server/fe/tsconfig.json b/bin/u_panel/src/server/fe/tsconfig.json new file mode 100644 index 0000000..f531992 --- /dev/null +++ b/bin/u_panel/src/server/fe/tsconfig.json @@ -0,0 +1,32 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "compileOnSave": false, + "compilerOptions": { + "baseUrl": "./", + "outDir": "./dist/out-tsc", + "forceConsistentCasingInFileNames": true, + "strict": true, + "noImplicitOverride": true, + "noPropertyAccessFromIndexSignature": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "sourceMap": true, + "declaration": false, + "downlevelIteration": true, + "experimentalDecorators": true, + "moduleResolution": "node", + "importHelpers": true, + "target": "es2017", + "module": "es2020", + "lib": [ + "es2020", + "dom" + ] + }, + "angularCompilerOptions": { + "enableI18nLegacyMessageIdFormat": false, + "strictInjectionParameters": true, + "strictInputAccessModifiers": true, + "strictTemplates": true + } +} diff --git a/bin/u_panel/src/server/fe/tsconfig.spec.json b/bin/u_panel/src/server/fe/tsconfig.spec.json new file mode 100644 index 0000000..092345b --- /dev/null +++ b/bin/u_panel/src/server/fe/tsconfig.spec.json @@ -0,0 +1,18 @@ +/* To learn more about this file see: https://angular.io/config/tsconfig. */ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "./out-tsc/spec", + "types": [ + "jasmine" + ] + }, + "files": [ + "src/test.ts", + "src/polyfills.ts" + ], + "include": [ + "src/**/*.spec.ts", + "src/**/*.d.ts" + ] +} diff --git a/bin/u_panel/src/server/mod.rs b/bin/u_panel/src/server/mod.rs new file mode 100644 index 0000000..58aef14 --- /dev/null +++ b/bin/u_panel/src/server/mod.rs @@ -0,0 +1,56 @@ +/* +Tabs: Agents, Tasks, Summary +every tab has list page and item page with more info/actions + +Agents: + +| id | alias | ..see struct | tasks done +| stripped | alias | ... | clickable number of assigned jobs + +almost all fields are editable, rows are deletable + +*/ + +use actix_web::{get, web, App, HttpResponse, HttpServer, Responder}; +use rust_embed::RustEmbed; +use std::borrow::Cow; +use u_lib::unwrap_enum; + +#[derive(RustEmbed)] +#[folder = "./src/server/fe/dist/fe/"] +struct Files; + +impl Files { + pub fn get_static(path: impl AsRef) -> Option<&'static [u8]> { + let file = Self::get(path.as_ref())?.data; + Some(unwrap_enum!(file, Cow::Borrowed)) + } +} + +#[get("/")] +async fn main_page() -> impl Responder { + let index = Files::get_static("index.html").unwrap(); + HttpResponse::Ok().body(index) +} + +#[get("/{file}")] +async fn static_files_adapter(file: web::Path<(String,)>) -> impl Responder { + let file = file.into_inner().0; + let mimetype = mime_guess::from_path(&file).first_or_octet_stream(); + match Files::get_static(file) { + Some(data) => HttpResponse::Ok() + .content_type(mimetype.to_string()) + .body(data), + None => HttpResponse::NotFound().finish(), + } +} + +#[actix_web::main] +pub async fn serve() -> std::io::Result<()> { + let addr = "127.0.0.1:8080"; + println!("Serving at http://{}", addr); + HttpServer::new(|| App::new().service(main_page).service(static_files_adapter)) + .bind(addr)? + .run() + .await +} diff --git a/bin/u_server/Cargo.toml b/bin/u_server/Cargo.toml index 043022a..d848850 100644 --- a/bin/u_server/Cargo.toml +++ b/bin/u_server/Cargo.toml @@ -41,4 +41,4 @@ path = "src/u_server.rs" [[bin]] name = "u_server" -path = "src/main.rs" \ No newline at end of file +path = "src/main.rs" diff --git a/lib/u_lib/src/errors/variants.rs b/lib/u_lib/src/errors/variants.rs index 48d2fbb..103afe1 100644 --- a/lib/u_lib/src/errors/variants.rs +++ b/lib/u_lib/src/errors/variants.rs @@ -66,8 +66,8 @@ pub enum UError { #[error("Panicked: {0}")] Panic(String), - #[error("UI error: {0}")] - TUIError(String), + #[error("Panel error: {0}")] + PanelError(String), } impl UError {