From 533e9e06e6ef4c1290c1517b3c6926acec444ecf Mon Sep 17 00:00:00 2001 From: Wyatt Herkamp Date: Wed, 21 Aug 2024 12:01:09 -0400 Subject: [PATCH] Browsing files on the frontend --- crates/core/src/storage/storage_path.rs | 8 +- .../src/app/api/repository/management.rs | 34 +++++-- site/package-lock.json | 52 +++++------ site/package.json | 4 +- .../repository/configs/FallBackEditor.vue | 2 +- .../configs/RepositoryPageEditor.vue | 2 +- site/src/components/form/JsonSchemaForm.vue | 9 ++ site/src/components/nav/NavBar.vue | 4 +- .../repository/browse/BrowseEntry.vue | 38 ++++++++ .../repository/browse/BrowseFile.vue | 46 ++++++++++ .../repository/browse/BrowseFolder.vue | 39 ++++++++ .../repository/browse/BrowseHeader.vue | 89 +++++++++++++++++++ .../repository/browse/BrowseList.vue | 50 +++++++++++ .../components/repository/browse/browse.scss | 14 +++ .../repository/project/BrowseProject.vue | 34 +++++++ .../types/maven/MavenProjectHelper.vue | 48 ++++++++++ .../types/maven/MavenRepositoryHelper.vue | 4 +- .../types/maven/MavenRepositoryHelpers.ts | 44 +++++++-- site/src/main.ts | 6 +- site/src/router/index.ts | 6 +- site/src/types/browse.ts | 39 ++++++++ site/src/types/project.ts | 41 +++++++++ site/src/types/repository.ts | 15 ++++ site/src/views/BrowseView.vue | 60 ++++++++++++- site/src/views/RepositoryPageView.vue | 16 ++++ 25 files changed, 651 insertions(+), 53 deletions(-) create mode 100644 site/src/components/repository/browse/BrowseEntry.vue create mode 100644 site/src/components/repository/browse/BrowseFile.vue create mode 100644 site/src/components/repository/browse/BrowseFolder.vue create mode 100644 site/src/components/repository/browse/BrowseHeader.vue create mode 100644 site/src/components/repository/browse/BrowseList.vue create mode 100644 site/src/components/repository/browse/browse.scss create mode 100644 site/src/components/repository/project/BrowseProject.vue create mode 100644 site/src/components/repository/types/maven/MavenProjectHelper.vue create mode 100644 site/src/types/browse.ts create mode 100644 site/src/types/project.ts diff --git a/crates/core/src/storage/storage_path.rs b/crates/core/src/storage/storage_path.rs index fbd7a496..c2906130 100644 --- a/crates/core/src/storage/storage_path.rs +++ b/crates/core/src/storage/storage_path.rs @@ -64,7 +64,13 @@ impl From<&str> for StoragePath { let value = value.split("/").collect::>(); let components = value .iter() - .map(|v| StoragePathComponent(v.to_string())) + .filter_map(|v| { + if v.is_empty() { + None + } else { + Some(StoragePathComponent(v.to_string())) + } + }) .collect::>(); StoragePath(components) } diff --git a/nitro_repo/src/app/api/repository/management.rs b/nitro_repo/src/app/api/repository/management.rs index 30e03d87..acfcd9f7 100644 --- a/nitro_repo/src/app/api/repository/management.rs +++ b/nitro_repo/src/app/api/repository/management.rs @@ -1,6 +1,6 @@ use ahash::HashMap; use axum::{ - extract::{Path, State}, + extract::{Path, Query, State}, response::{IntoResponse, Response}, routing::{get, post, put}, Json, Router, @@ -121,6 +121,7 @@ pub async fn new_repository( .body(serde_json::to_string(&db_repository).unwrap().into()) .unwrap()) } + #[utoipa::path( get, path = "/{repository}/configs", @@ -147,6 +148,11 @@ pub async fn get_configs_for_repository( .status(StatusCode::OK) .json_body(&repository) } +#[derive(Deserialize, Default, Debug)] +#[serde(default)] +pub struct GetConfigParams { + default: bool, +} #[utoipa::path( get, path = "/{repository}/config/{config_key}", @@ -158,19 +164,35 @@ pub async fn get_configs_for_repository( pub async fn get_config( State(site): State, auth: Authentication, + Query(params): Query, Path((repository, config)): Path<(Uuid, String)>, ) -> Result { if !auth.can_edit_repository(repository) { return Ok(MissingPermission::EditRepository(repository).into_response()); } - let Some(config) = - GenericDBRepositoryConfig::get_config(repository, config, site.as_ref()).await? - else { - return Ok(RepositoryNotFound::Uuid(repository).into_response()); + let config = match GenericDBRepositoryConfig::get_config(repository, &config, site.as_ref()) + .await? + { + Some(config) => config.value.0, + None => { + if params.default { + let Some(config_type) = site.get_repository_config_type(&config) else { + return Ok(InvalidRepositoryConfig::InvalidConfigType(config).into_response()); + }; + match config_type.default() { + Ok(ok) => ok, + Err(_) => { + return Ok(RepositoryNotFound::Uuid(repository).into_response()); + } + } + } else { + return Ok(RepositoryNotFound::Uuid(repository).into_response()); + } + } }; Response::builder() .status(StatusCode::OK) - .json_body(&config.value.0) + .json_body(&config) } /// Updates a config for a repository /// diff --git a/site/package-lock.json b/site/package-lock.json index 9ca7d599..b860f325 100644 --- a/site/package-lock.json +++ b/site/package-lock.json @@ -37,7 +37,7 @@ "vue3-simple-icons": "^13.2.0" }, "devDependencies": { - "@chromatic-com/storybook": "^1.6.1", + "@chromatic-com/storybook": "^1.7.0", "@rushstack/eslint-patch": "^1.10.4", "@storybook/addon-essentials": "^8.2.9", "@storybook/addon-interactions": "^8.2.9", @@ -62,7 +62,7 @@ "sass": "^1.77", "storybook": "^8.2.9", "typescript": "~5.5.4", - "vite": "^5.4.1", + "vite": "^5.4.2", "vite-plugin-vue-devtools": "^7.3.8", "vue-tsc": "^2.0.29" } @@ -2153,9 +2153,9 @@ } }, "node_modules/@chromatic-com/storybook": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/@chromatic-com/storybook/-/storybook-1.6.1.tgz", - "integrity": "sha512-x1x1NB3j4xpfeSWKr96emc+7ZvfsvH+/WVb3XCjkB24PPbT8VZXb3mJSAQMrSzuQ8+eQE9kDogYHH9Fj3tb/Cw==", + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@chromatic-com/storybook/-/storybook-1.7.0.tgz", + "integrity": "sha512-0aAkSaNsHaJL37/r+TIbpKjCouIysvoJno61LzUSs1xW4fpxF7gdr8xwIOONQjEsz2Fa0uFHXmzkFYcH6o8kmA==", "dev": true, "license": "MIT", "dependencies": { @@ -4473,9 +4473,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.4.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.4.1.tgz", - "integrity": "sha512-1tbpb9325+gPnKK0dMm+/LMriX0vKxf6RnB0SZUqfyVkQ4fMgUSySqhxE/y8Jvs4NyF1yHzTfG9KlnkIODxPKg==", + "version": "22.4.2", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.4.2.tgz", + "integrity": "sha512-nAvM3Ey230/XzxtyDcJ+VjvlzpzoHwLsF7JaDRfoI0ytO0mVheerNmM45CtA0yOILXwXXxOrcUWH3wltX+7PSw==", "dev": true, "license": "MIT", "dependencies": { @@ -4504,9 +4504,9 @@ "license": "MIT" }, "node_modules/@types/react": { - "version": "18.3.3", - "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.3.tgz", - "integrity": "sha512-hti/R0pS0q1/xx+TsI73XIqk26eBsISZ2R0wUijXIngRK9R/e7Xw/cXVxQK7R5JjW+SV4zGcn5hXjudkN/pLIw==", + "version": "18.3.4", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.4.tgz", + "integrity": "sha512-J7W30FTdfCxDDjmfRM+/JqLHBIyl7xUIp9kwK637FGmY7+mkSFSe6L4jpZzhj5QMfLssSDP4/i75AKkrdC7/Jw==", "dev": true, "license": "MIT", "dependencies": { @@ -6437,9 +6437,9 @@ } }, "node_modules/core-js-compat": { - "version": "3.38.0", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.38.0.tgz", - "integrity": "sha512-75LAicdLa4OJVwFxFbQR3NdnZjNgX6ILpVcVzcC4T2smerB5lELMrJQQQoWV6TiuC/vlaFqgU2tKQx9w5s0e0A==", + "version": "3.38.1", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.38.1.tgz", + "integrity": "sha512-JRH6gfXxGmrzF3tZ57lFx97YARxCXPaMzPo6jELZhv88pBH5VXpQ+y0znKGlFnzuaihqhLbefxSJxWJMPtfDzw==", "dev": true, "license": "MIT", "dependencies": { @@ -6778,9 +6778,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.11", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.11.tgz", - "integrity": "sha512-R1CccCDYqndR25CaXFd6hp/u9RaaMcftMkphmvuepXr5b1vfLkRml6aWVeBhXJ7rbevHkKEMJtz8XqPf7ffmew==", + "version": "1.5.13", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.13.tgz", + "integrity": "sha512-lbBcvtIJ4J6sS4tb5TLp1b4LyfCdMkwStzXPyAgVgTRAsep4bvrAGaBOP7ZJtQMNJpSQ9SqG4brWOroNaQtm7Q==", "dev": true, "license": "ISC" }, @@ -13356,15 +13356,15 @@ } }, "node_modules/vite": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.1.tgz", - "integrity": "sha512-1oE6yuNXssjrZdblI9AfBbHCC41nnyoVoEZxQnID6yvQZAFBzxxkqoFLtHUMkYunL8hwOLEjgTuxpkRxvba3kA==", + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.2.tgz", + "integrity": "sha512-dDrQTRHp5C1fTFzcSaMxjk6vdpKvT+2/mIdE07Gw2ykehT49O0z/VHS3zZ8iV/Gh8BJJKHWOe5RjaNrW5xf/GA==", "dev": true, "license": "MIT", "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.41", - "rollup": "^4.13.0" + "rollup": "^4.20.0" }, "bin": { "vite": "bin/vite.js" @@ -13429,16 +13429,16 @@ } }, "node_modules/vite-plugin-inspect": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/vite-plugin-inspect/-/vite-plugin-inspect-0.8.5.tgz", - "integrity": "sha512-JvTUqsP1JNDw0lMZ5Z/r5cSj81VK2B7884LO1DC3GMBhdcjcsAnJjdWq7bzQL01Xbh+v60d3lju3g+z7eAtNew==", + "version": "0.8.6", + "resolved": "https://registry.npmjs.org/vite-plugin-inspect/-/vite-plugin-inspect-0.8.6.tgz", + "integrity": "sha512-iM/smnFRSuDq9UMVAN06fqBbHAofGDtB5yBucsl0QnPCFqQ2TmPIbsSgSR3gUv13qJ8oPE/FFhXlm9g1xX9nzg==", "dev": true, "license": "MIT", "dependencies": { "@antfu/utils": "^0.7.10", "@rollup/pluginutils": "^5.1.0", - "debug": "^4.3.5", - "error-stack-parser-es": "^0.1.4", + "debug": "^4.3.6", + "error-stack-parser-es": "^0.1.5", "fs-extra": "^11.2.0", "open": "^10.1.0", "perfect-debounce": "^1.0.0", diff --git a/site/package.json b/site/package.json index 71d85800..313fed68 100644 --- a/site/package.json +++ b/site/package.json @@ -44,7 +44,7 @@ "vue3-simple-icons": "^13.2.0" }, "devDependencies": { - "@chromatic-com/storybook": "^1.6.1", + "@chromatic-com/storybook": "^1.7.0", "@rushstack/eslint-patch": "^1.10.4", "@storybook/addon-essentials": "^8.2.9", "@storybook/addon-interactions": "^8.2.9", @@ -69,7 +69,7 @@ "sass": "^1.77", "storybook": "^8.2.9", "typescript": "~5.5.4", - "vite": "^5.4.1", + "vite": "^5.4.2", "vite-plugin-vue-devtools": "^7.3.8", "vue-tsc": "^2.0.29" } diff --git a/site/src/components/admin/repository/configs/FallBackEditor.vue b/site/src/components/admin/repository/configs/FallBackEditor.vue index 0c9a17dd..7a2f7abd 100644 --- a/site/src/components/admin/repository/configs/FallBackEditor.vue +++ b/site/src/components/admin/repository/configs/FallBackEditor.vue @@ -40,7 +40,7 @@ async function load() { }) if (props.repository) { await http - .get(`/api/repository/repository/${props.repository}/config/${props.settingName}`) + .get(`/api/repository/${props.repository}/config/${props.settingName}?default=true`) .then((response) => { model.value = response.data }) diff --git a/site/src/components/admin/repository/configs/RepositoryPageEditor.vue b/site/src/components/admin/repository/configs/RepositoryPageEditor.vue index e675b47e..5124d502 100644 --- a/site/src/components/admin/repository/configs/RepositoryPageEditor.vue +++ b/site/src/components/admin/repository/configs/RepositoryPageEditor.vue @@ -4,7 +4,7 @@
Browse + Repositories diff --git a/site/src/components/repository/browse/BrowseEntry.vue b/site/src/components/repository/browse/BrowseEntry.vue new file mode 100644 index 00000000..864dad23 --- /dev/null +++ b/site/src/components/repository/browse/BrowseEntry.vue @@ -0,0 +1,38 @@ + + + diff --git a/site/src/components/repository/browse/BrowseFile.vue b/site/src/components/repository/browse/BrowseFile.vue new file mode 100644 index 00000000..5379d68e --- /dev/null +++ b/site/src/components/repository/browse/BrowseFile.vue @@ -0,0 +1,46 @@ + + + diff --git a/site/src/components/repository/browse/BrowseFolder.vue b/site/src/components/repository/browse/BrowseFolder.vue new file mode 100644 index 00000000..9a6d16f6 --- /dev/null +++ b/site/src/components/repository/browse/BrowseFolder.vue @@ -0,0 +1,39 @@ + + + diff --git a/site/src/components/repository/browse/BrowseHeader.vue b/site/src/components/repository/browse/BrowseHeader.vue new file mode 100644 index 00000000..26d895e4 --- /dev/null +++ b/site/src/components/repository/browse/BrowseHeader.vue @@ -0,0 +1,89 @@ + + + + diff --git a/site/src/components/repository/browse/BrowseList.vue b/site/src/components/repository/browse/BrowseList.vue new file mode 100644 index 00000000..a0aff3d7 --- /dev/null +++ b/site/src/components/repository/browse/BrowseList.vue @@ -0,0 +1,50 @@ + + + diff --git a/site/src/components/repository/browse/browse.scss b/site/src/components/repository/browse/browse.scss new file mode 100644 index 00000000..a0704116 --- /dev/null +++ b/site/src/components/repository/browse/browse.scss @@ -0,0 +1,14 @@ +@import '@/assets/styles/theme.scss'; +.browseItem { + color: $text; + + display: flex; + justify-content: space-between; + padding: 10px; + flex-direction: row; + border: 1px solid #e0e0e0; + &:hover { + border: 1px solid $primary; + cursor: pointer; + } +} diff --git a/site/src/components/repository/project/BrowseProject.vue b/site/src/components/repository/project/BrowseProject.vue new file mode 100644 index 00000000..71b10b11 --- /dev/null +++ b/site/src/components/repository/project/BrowseProject.vue @@ -0,0 +1,34 @@ + + diff --git a/site/src/components/repository/types/maven/MavenProjectHelper.vue b/site/src/components/repository/types/maven/MavenProjectHelper.vue new file mode 100644 index 00000000..39817c38 --- /dev/null +++ b/site/src/components/repository/types/maven/MavenProjectHelper.vue @@ -0,0 +1,48 @@ + + + + + diff --git a/site/src/components/repository/types/maven/MavenRepositoryHelper.vue b/site/src/components/repository/types/maven/MavenRepositoryHelper.vue index f575c03e..1be93840 100644 --- a/site/src/components/repository/types/maven/MavenRepositoryHelper.vue +++ b/site/src/components/repository/types/maven/MavenRepositoryHelper.vue @@ -14,7 +14,7 @@