Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement locha Api locha change to support 1:1 objects. #225

Merged
merged 5 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions components/LoChaItem.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { LoCha, ObjType } from '~/libs/types'
import type { LoCha } from '~/libs/types'

const props = defineProps<{
projectSlug: string
item: LoCha
}>()

defineEmits<{
(e: 'accept', id: { id: number, objtype: ObjType }): void
(e: 'accept', id: number): void
}>()

const lochaCount = computed(() => props.item.objects.length)
Expand All @@ -20,21 +20,24 @@ const isProjectUser = computed(() => {

<template>
<el-card style="--el-card-bg-color: #FAFAFA;" :body-style="{ padding: 0 }">
<template v-if="lochaCount > 1" #header>
<template v-if="lochaCount > 1 || isProjectUser" #header>
<div class="card-header">
<el-text class="mx-1" size="large" tag="b">
<el-text v-if="lochaCount > 1" class="mx-1" size="large" tag="b">
{{ $t('logs.object_count', { n: lochaCount }) }}
</el-text>
<el-button-group v-if="isProjectUser">
<el-button type="primary" @click="$emit('accept', item.id)">
</el-button>
</el-button-group>
</div>
</template>
<el-space wrap fill style="width: 100%">
<log-item
v-for="log in item.objects"
:key="log.id"
v-for="(log, i) in item.objects"
:key="i"
:log="log"
:project="projectSlug"
:project-user="isProjectUser"
@accept="$emit('accept', $event)"
/>
</el-space>
</el-card>
Expand Down
4 changes: 2 additions & 2 deletions components/LoChaList.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<script setup lang="ts">
import type { LoCha, ObjType } from '~/libs/types'
import type { LoCha } from '~/libs/types'

const props = defineProps<{
projectSlug: string
loChas: LoCha[]
}>()

defineEmits<{
(e: 'accept', id: { id: number, objtype: ObjType }): void
(e: 'accept', id: number): void
}>()

const scrollCount = ref<number>(10)
Expand Down
2 changes: 1 addition & 1 deletion components/LogFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const statUsers = computed(() => {
const users = logs.value
.map((log) =>
uniq(
(log.base ? log.changesets.slice(1) : log.changesets).map(
(log.changesets ? log.base ? log.changesets.slice(1) : log.changesets : []).map(
(changeset) => changeset.user,
),
),
Expand Down
151 changes: 65 additions & 86 deletions components/LogItem.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
<script setup lang="ts">
import LazyComponent from 'v-lazy-component'
import { compact, uniq } from 'underscore'
import type { Log, ObjType } from '~/libs/types'
import { objTypeFull } from '~/libs/types'

const props = defineProps<{
log: Log
project: string
projectUser: boolean
}>()

defineEmits<{
(e: 'accept', id: { id: number, objtype: ObjType }): void
}>()

const logSorted = computed(() => {
Expand All @@ -21,33 +17,38 @@ const logSorted = computed(() => {
function objtypeFull(objtype: ObjType) {
return objTypeFull(objtype)
}

function uniqHistoryIds(log: Log) {
return uniq(
compact([log.base, log.change])
.map((object) => ({ objtype: object.objtype, id: object.id })),
(object) => `${object.objtype}${object.id}`,
)
}
</script>

<template>
<el-card shadow="never">
<template #header>
<div class="card-header">
<span>
<a
:href="`https://www.openstreetmap.org/${objtypeFull(log.objtype)}/${log.id}/history`"
target="_blank"
>
{{ log.objtype }}{{ log.id }}
</a>
-
{{ log.base?.tags.name || log.change.tags.name }}
</span>
<template v-for="object in uniqHistoryIds(log)">
<span v-if="object" :key="`${object.objtype}${object.id}`">
<a
:href="`https://www.openstreetmap.org/${objtypeFull(object.objtype)}/${object.id}/history`"
target="_blank"
>
{{ object.objtype }}{{ object.id }}
</a>
-
{{ log.base?.tags.name || log.change.tags.name }}
</span>
</template>
wazolab marked this conversation as resolved.
Show resolved Hide resolved
<span v-if="!log.base">
<el-tag
type="success"
size="small"
:disable-transitions="true"
class="item"
>
<el-tag type="success" size="small" :disable-transitions="true" class="item">
{{ $t('logs.created') }}
</el-tag>
</span>
<span v-if="log.diff_attribs && log.diff_attribs.deleted">
<span v-if="log.diff_attribs && log.diff_attribs.deleted?.length">
<el-tag
type="danger"
size="small"
Expand All @@ -61,20 +62,11 @@ function objtypeFull(objtype: ObjType) {
<el-tag
v-for="text in [
...new Set(log.matches.map((m) => m.user_groups).flat()),
].sort()"
:key="text"
size="small"
class="item"
].sort()" :key="text" size="small" class="item"
>
📌 {{ text }}
</el-tag>
<el-tag
v-for="match in logSorted"
:key="match.selectors.join(';')"
size="small"
type="warning"
class="item"
>
<el-tag v-for="match in logSorted" :key="match.selectors.join(';')" size="small" type="warning" class="item">
<div>
🏷️ {{ $i18nHash(match.name) }}
<br v-if="$i18nHash(match.name) !== undefined" />
Expand All @@ -85,60 +77,45 @@ function objtypeFull(objtype: ObjType) {
</div>
</el-tag>
</span>
<el-button-group>
<el-button
tag="a"
size="small"
:href="`https://www.openstreetmap.org/edit?editor=id&${objtypeFull(
log.objtype,
)}=${log.id}`"
target="_blank"
>
OSM iD
</el-button>

<el-button
tag="a"
size="small"
:href="`http://127.0.0.1:8111/load_object?objects=${log.objtype}${log.id}`"
target="hidden_josm_target"
>
JOSM
</el-button>
<template v-for="object in uniqHistoryIds(log)">
<el-button-group v-if="object" :key="`${object.objtype}${object.id}`">
<el-button
tag="a" size="small" :href="`https://www.openstreetmap.org/edit?editor=id&${objtypeFull(
object.objtype,
)}=${object.id}`" target="_blank"
>
OSM iD
</el-button>

<el-button
tag="a"
size="small"
target="_blank"
:href="`https://osmlab.github.io/osm-deep-history/#/${objtypeFull(
log.objtype,
)}/${log.id}`"
title="OSM Deep History"
>
Deep H
</el-button>
<el-button
tag="a" size="small"
:href="`http://127.0.0.1:8111/load_object?objects=${object.objtype}${object.id}`"
target="hidden_josm_target"
>
JOSM
</el-button>

<el-button
tag="a"
size="small"
target="_blank"
:href="`https://pewu.github.io/osm-history/#/${objtypeFull(
log.objtype,
)}/${log.id}`"
title="OSM History Viewer"
>
OSM H
</el-button>
</el-button-group>
<el-button
tag="a" size="small" target="_blank" :href="`https://osmlab.github.io/osm-deep-history/#/${objtypeFull(
object.objtype,
)}/${object.id}`" title="OSM Deep History"
>
Deep H
</el-button>

<el-button-group v-if="projectUser">
<el-button
type="primary"
@click="$emit('accept', { id: log.id, objtype: log.objtype })"
>
</el-button>
</el-button-group>
<el-button
tag="a"
size="small"
target="_blank"
:href="`https://pewu.github.io/osm-history/#/${objtypeFull(
object.objtype,
)}/${object.id}`"
title="OSM History Viewer"
>
OSM H
</el-button>
</el-button-group>
</template>
</div>
</template>
<el-row :gutter="20">
Expand All @@ -148,14 +125,16 @@ function objtypeFull(objtype: ObjType) {
</template>v{{
log.change.version
}}
<changesets :changesets="log.base ? log.changesets.slice(1) : log.changesets" />
<changesets v-if="log.changesets" :changesets="log.base ? log.changesets.slice(1) : log.changesets" />
</el-col>
<el-col :span="7">
<diff
:src="log.base"
:dst="log.change"
:diff="log.diff_attribs || {}"
:exclude="[
'objtype',
'id',
'tags',
'version',
'changeset_id',
Expand All @@ -164,7 +143,7 @@ function objtypeFull(objtype: ObjType) {
'username',
'deleted',
'geom',
...(log.objtype !== 'r' ? ['members'] : []),
'members',
]"
:clear="['members', 'geom']"
/>
Expand Down
6 changes: 3 additions & 3 deletions libs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface Member {
}

export interface Subject extends Record<string, any> {
objtype: ObjType
id: number
version: number
deleted: boolean
changeset_id: number
Expand Down Expand Up @@ -60,13 +62,11 @@ export type LogActionOptions = Record<string, string | string[] | object>
export type Action = [string, LogAction | null, LogActionOptions | null]
export type Actions = Record<Key, Action[]>
export interface Log {
objtype: ObjType
id: number
base?: Subject
change: Subject
matches: Match[]
action: LogAction
changesets: Changeset[]
changesets?: Changeset[]
diff_attribs?: Actions
diff_tags?: Actions
}
Expand Down
Loading