Skip to content

Commit

Permalink
Merge pull request #85 from SquirrelCorporation/feat-debug-settings
Browse files Browse the repository at this point in the history
Add feature to delete and resync playbooks
  • Loading branch information
SquirrelDeveloper authored Jul 5, 2024
2 parents 0da8307 + 77841cb commit 6943c56
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
1 change: 1 addition & 0 deletions client/src/components/Template/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum SettingsSubTitleColors {
SERVER = '#8e7d50',
GIT = '#336048',
LOCAL = '#4b4a4a',
DEBUG = '#b614b6',
}

export type PageContainerTitleProps = {
Expand Down
38 changes: 33 additions & 5 deletions client/src/pages/Admin/Settings/components/AdvancedSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ import {
deleteAnsibleLogs,
deleteContainerStats,
deleteDeviceStats,
deletePlaybooksAndResync,
deleteServerLogs,
postRestartServer,
} from '@/services/rest/settings';
import {
InfoCircleFilled,
RedoOutlined,
TableOutlined,
} from '@ant-design/icons';
import { BugFilled, InfoCircleFilled, RedoOutlined } from '@ant-design/icons';
import { Button, Card, Flex, Popover, Space, Typography } from 'antd';
import { DeleteOutline } from 'antd-mobile-icons';
import React from 'react';
Expand Down Expand Up @@ -161,6 +158,37 @@ const AdvancedSettings: React.FC = () => {
</Space>
</Flex>
</Card>
<Card
type="inner"
style={{ marginTop: 16 }}
title={
<Title.SubTitle
title={'Debug'}
backgroundColor={SettingsSubTitleColors.DEBUG}
icon={<BugFilled />}
/>
}
>
<Flex vertical gap={32} style={{ width: '50%' }}>
<Space direction="horizontal" size="middle">
<Typography>
{' '}
<Popover content={'Delete all playbooks and resync'}>
<InfoCircleFilled />
</Popover>{' '}
Playbooks
</Typography>{' '}
<Button
danger
icon={<DeleteOutline />}
onClick={async () => await deletePlaybooksAndResync()}
>
Purge & Sync again
</Button>
<Space.Compact style={{ width: '100%' }} />
</Space>
</Flex>
</Card>
</Card>
);
};
Expand Down
11 changes: 11 additions & 0 deletions client/src/services/rest/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ export async function deleteDeviceStats(options?: Record<string, any>) {
});
}

export async function deletePlaybooksAndResync(options?: Record<string, any>) {
return request<API.SimpleResult>(
`/api/settings/advanced/playbooks-and-resync`,
{
method: 'DELETE',
...{},
...(options || {}),
},
);
}

export async function postContainerStatsSettings(
type: string,
value: number,
Expand Down
3 changes: 2 additions & 1 deletion server/src/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
deleteContainerStats,
deleteDeviceStats,
deleteLogs,
deletePlaybooksModelAndResync,
postRestartServer,
} from '../services/settings/advanced';

Expand All @@ -36,5 +37,5 @@ router.delete('/advanced/logs', deleteLogs);
router.delete('/advanced/ansible-logs', deleteAnsibleLogs);
router.delete('/advanced/device-stats', deleteDeviceStats);
router.delete('/advanced/container-stats', deleteContainerStats);

router.delete('/advanced/playbooks-and-resync', deletePlaybooksModelAndResync);
export default router;
12 changes: 12 additions & 0 deletions server/src/services/settings/advanced.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { SuccessResponse } from '../../core/api/ApiResponse';
import {
COLLECTION_NAME as PlaybookCollectionName,
PlaybookModel,
} from '../../data/database/model/Playbook';
import AnsibleLogsRepo from '../../data/database/repository/AnsibleLogsRepo';
import ContainerStatsRepo from '../../data/database/repository/ContainerStatsRepo';
import DeviceStatRepo from '../../data/database/repository/DeviceStatRepo';
import LogsRepo from '../../data/database/repository/LogsRepo';
import asyncHandler from '../../helpers/AsyncHandler';
import { restart } from '../../index';
import PlaybooksRepositoryEngine from '../../integrations/playbooks-repository/PlaybooksRepositoryEngine';

export const postRestartServer = asyncHandler(async (req, res) => {
await restart();
Expand All @@ -29,3 +34,10 @@ export const deleteDeviceStats = asyncHandler(async (req, res) => {
await DeviceStatRepo.deleteAll();
new SuccessResponse('Device stats Purged Successfully').send(res);
});

export const deletePlaybooksModelAndResync = asyncHandler(async (req, res) => {
await PlaybookModel.db.collection(PlaybookCollectionName).drop();
await PlaybooksRepositoryEngine.registerRepositories();
await PlaybooksRepositoryEngine.syncAllRegistered();
new SuccessResponse('All data purged successfully').send(res);
});

0 comments on commit 6943c56

Please sign in to comment.