Move relationship types + dashboard recent off the machines blueprint
- Add /api/assets/relationshiptypes (GET/POST) serving RelationshipType; point relationshipTypesApi at it instead of the legacy /api/machines blueprint. - Dashboard recent-devices widget reads assetsApi.list (asset shape) instead of machinesApi. No frontend code references machinesApi anymore. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -176,10 +176,10 @@ export const computersApi = {
|
|||||||
// Relationship Types API
|
// Relationship Types API
|
||||||
export const relationshipTypesApi = {
|
export const relationshipTypesApi = {
|
||||||
list() {
|
list() {
|
||||||
return api.get('/machines/relationshiptypes')
|
return api.get('/assets/relationshiptypes')
|
||||||
},
|
},
|
||||||
create(data) {
|
create(data) {
|
||||||
return api.post('/machines/relationshiptypes', data)
|
return api.post('/assets/relationshiptypes', data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,18 +65,18 @@
|
|||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Asset #</th>
|
||||||
<th>Category</th>
|
|
||||||
<th>Type</th>
|
<th>Type</th>
|
||||||
|
<th>Status</th>
|
||||||
<th>Business Unit</th>
|
<th>Business Unit</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr v-for="machine in recentMachines" :key="machine.machineid">
|
<tr v-for="machine in recentMachines" :key="machine.assetid">
|
||||||
<td>{{ machine.machinenumber || machine.hostname || machine.alias || '-' }}</td>
|
<td>{{ machine.assetnumber || machine.name || '-' }}</td>
|
||||||
<td>{{ machine.category || '-' }}</td>
|
<td>{{ machine.assettypename || '-' }}</td>
|
||||||
<td>{{ machine.machinetype || '-' }}</td>
|
<td>{{ machine.statusname || '-' }}</td>
|
||||||
<td>{{ machine.businessunit || '-' }}</td>
|
<td>{{ machine.businessunitname || '-' }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr v-if="recentMachines.length === 0">
|
<tr v-if="recentMachines.length === 0">
|
||||||
<td colspan="4" style="text-align: center; color: var(--text-light);">
|
<td colspan="4" style="text-align: center; color: var(--text-light);">
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted } from 'vue'
|
import { ref, onMounted } from 'vue'
|
||||||
import { dashboardApi, machinesApi, printersApi } from '../api'
|
import { dashboardApi, assetsApi, printersApi } from '../api'
|
||||||
|
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const stats = ref({})
|
const stats = ref({})
|
||||||
@@ -104,7 +104,7 @@ onMounted(async () => {
|
|||||||
try {
|
try {
|
||||||
const [dashRes, machinesRes, printersRes] = await Promise.all([
|
const [dashRes, machinesRes, printersRes] = await Promise.all([
|
||||||
dashboardApi.summary().catch(() => ({ data: { data: {} } })),
|
dashboardApi.summary().catch(() => ({ data: { data: {} } })),
|
||||||
machinesApi.list({ perpage: 5 }).catch(() => ({ data: { data: [] } })),
|
assetsApi.list({ perpage: 5 }).catch(() => ({ data: { data: [] } })),
|
||||||
printersApi.dashboardSummary().catch(() => ({ data: { data: {} } }))
|
printersApi.dashboardSummary().catch(() => ({ data: { data: {} } }))
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|||||||
@@ -203,6 +203,51 @@ def delete_asset_status(status_id: int):
|
|||||||
return success_response(message='Asset status deleted')
|
return success_response(message='Asset status deleted')
|
||||||
|
|
||||||
|
|
||||||
|
# =============================================================================
|
||||||
|
# Relationship Types
|
||||||
|
# =============================================================================
|
||||||
|
|
||||||
|
@assets_bp.route('/relationshiptypes', methods=['GET'])
|
||||||
|
@jwt_required(optional=True)
|
||||||
|
def list_relationship_types():
|
||||||
|
"""List all asset relationship types."""
|
||||||
|
types = RelationshipType.query.order_by(RelationshipType.relationshiptype).all()
|
||||||
|
return success_response([{
|
||||||
|
'relationshiptypeid': t.relationshiptypeid,
|
||||||
|
'relationshiptype': t.relationshiptype,
|
||||||
|
'description': t.description
|
||||||
|
} for t in types])
|
||||||
|
|
||||||
|
|
||||||
|
@assets_bp.route('/relationshiptypes', methods=['POST'])
|
||||||
|
@jwt_required()
|
||||||
|
def create_relationship_type():
|
||||||
|
"""Create a new asset relationship type."""
|
||||||
|
data = request.get_json()
|
||||||
|
if not data or not data.get('relationshiptype'):
|
||||||
|
return error_response(ErrorCodes.VALIDATION_ERROR, 'relationshiptype is required')
|
||||||
|
|
||||||
|
if RelationshipType.query.filter_by(relationshiptype=data['relationshiptype']).first():
|
||||||
|
return error_response(
|
||||||
|
ErrorCodes.CONFLICT,
|
||||||
|
f"Relationship type '{data['relationshiptype']}' already exists",
|
||||||
|
http_code=409
|
||||||
|
)
|
||||||
|
|
||||||
|
rel_type = RelationshipType(
|
||||||
|
relationshiptype=data['relationshiptype'],
|
||||||
|
description=data.get('description')
|
||||||
|
)
|
||||||
|
db.session.add(rel_type)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
return success_response({
|
||||||
|
'relationshiptypeid': rel_type.relationshiptypeid,
|
||||||
|
'relationshiptype': rel_type.relationshiptype,
|
||||||
|
'description': rel_type.description
|
||||||
|
}, message='Relationship type created', http_code=201)
|
||||||
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Assets
|
# Assets
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user