Skip to content

Commit

Permalink
Browsing files on the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Aug 21, 2024
1 parent 322f58f commit 533e9e0
Show file tree
Hide file tree
Showing 25 changed files with 651 additions and 53 deletions.
8 changes: 7 additions & 1 deletion crates/core/src/storage/storage_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ impl From<&str> for StoragePath {
let value = value.split("/").collect::<Vec<&str>>();
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::<Vec<StoragePathComponent>>();
StoragePath(components)
}
Expand Down
34 changes: 28 additions & 6 deletions nitro_repo/src/app/api/repository/management.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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}",
Expand All @@ -158,19 +164,35 @@ pub async fn get_configs_for_repository(
pub async fn get_config(
State(site): State<NitroRepo>,
auth: Authentication,
Query(params): Query<GetConfigParams>,
Path((repository, config)): Path<(Uuid, String)>,
) -> Result<Response, InternalError> {
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
///
Expand Down
52 changes: 26 additions & 26 deletions site/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div v-if="input.page_type === PageType.Markdown" id="markdownEditor">
<MilkdownProvider>
<MarkdownEditor
:value="input.content"
:value="input.content || ''"
@update="
(content: string) => {
input.content = content
Expand Down
9 changes: 9 additions & 0 deletions site/src/components/form/JsonSchemaForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { EnumInput, SchemaForm, type FormInputType } from 'nitro-jsf'
import { computed, type Component, type PropType } from 'vue'
import TextInput from './text/TextInput.vue'
import DropDown from './dropdown/DropDown.vue'
import SwitchInput from './SwitchInput.vue'
const props = defineProps({
form: Object as PropType<SchemaForm>
Expand Down Expand Up @@ -64,6 +65,14 @@ function formFieldToInput(field: FormInputType): Input | undefined {
}
}
}
case 'boolean': {
return {
component: SwitchInput,
label: field.title() ?? field.key(),
id: field.key(),
props: {}
}
}
default:
console.error(`Unsupported field type: ${field.type()}`)
return undefined
Expand Down
4 changes: 1 addition & 3 deletions site/src/components/nav/NavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
<span>Nitro Repository</span>
</router-link>
</div>
<RouterLink class="navLink" :to="{ name: 'browse' }" title="Browse Repositories"
>Browse</RouterLink
>

<RouterLink class="navLink" :to="{ name: 'repositories' }" title="Browse Repositories"
>Repositories</RouterLink
>
Expand Down
38 changes: 38 additions & 0 deletions site/src/components/repository/browse/BrowseEntry.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<BrowseFile
v-if="props.file.type === 'File'"
:file="props.file.value as RawFile"
:currentPath="props.currentPath"
:repository="props.repository" />
<BrowseFolder
v-else-if="props.file.type === 'Directory'"
:file="props.file.value as RawDirectory"
:currentPath="props.currentPath"
:repository="props.repository" />
</template>

<script setup lang="ts">
import { apiURL } from '@/config'
import router from '@/router'
import { fixCurrentPath, type RawBrowseFile, type RawDirectory, type RawFile } from '@/types/browse'
import { createRepositoryRoute, type RepositoryWithStorageName } from '@/types/repository'
import { computed, type PropType } from 'vue'
import BrowseFolder from './BrowseFolder.vue'
import BrowseFile from './BrowseFile.vue'
const props = defineProps({
file: {
type: Object as PropType<RawBrowseFile>,
required: true
},
currentPath: {
type: String,
required: true
},
repository: {
type: Object as PropType<RepositoryWithStorageName>,
required: true
}
})
console.log(props.file)
</script>
46 changes: 46 additions & 0 deletions site/src/components/repository/browse/BrowseFile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<template>
<div @click="click" class="browseItem" data-type="file">
<div class="itemAndName">
<font-awesome-icon :icon="fileIcon" />
{{ props.file.name }}
</div>

<div>
{{ props.file.modified }}
</div>
</div>
</template>

<script setup lang="ts">
import { apiURL } from '@/config'
import router from '@/router'
import { fixCurrentPath, type RawBrowseFile, type RawFile } from '@/types/browse'
import { createRepositoryRoute, type RepositoryWithStorageName } from '@/types/repository'
import { computed, type PropType } from 'vue'
import './browse.scss'
const props = defineProps({
file: {
type: Object as PropType<RawFile>,
required: true
},
currentPath: {
type: String,
required: true
},
repository: {
type: Object as PropType<RepositoryWithStorageName>,
required: true
}
})
const fixedPath = fixCurrentPath(props.currentPath)
const repositoryURL = createRepositoryRoute(props.repository, `${fixedPath}/${props.file.name}`)
const fileIcon = computed(() => {
// TODO: More icons
return 'fa-solid fa-file'
})
function click() {
window.open(repositoryURL, '_blank')
}
</script>
Loading

0 comments on commit 533e9e0

Please sign in to comment.