Skip to content

Commit

Permalink
trying to dockerize, add todoist sync button
Browse files Browse the repository at this point in the history
  • Loading branch information
Micah Fitzgerald committed Aug 23, 2024
1 parent eb86093 commit 41968ac
Show file tree
Hide file tree
Showing 19 changed files with 228 additions and 89 deletions.
30 changes: 0 additions & 30 deletions Dockerfile

This file was deleted.

16 changes: 16 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM python:slim AS backend

COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

WORKDIR /app

COPY ./ ./

RUN uv sync
ENV VIRTUAL_ENV=/app/.venv
# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

CMD ["fastapi", "run", "main/main.py", "--port", "80"]

EXPOSE 80
13 changes: 13 additions & 0 deletions backend/main/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ async def complete_task(
return updated


@router.post(
"/api/v1/machines/{machine_id}/tasks/{task_id}/sync", response_model=TaskSchema
)
async def sync_to_todoist(
machine_id: str,
task_id: str,
service: ConvoyService = Depends(get_service),
) -> TaskSchema:
task = await service.get_task(machine_id, task_id)
task, td_task = await service.reconcile_task(machine_id, task)
return await service.task_to_schema(task)


@router.patch("/api/v1/supplies/{supply_id}", response_model=SupplySchema)
async def update_supply(
supply_id: str,
Expand Down
17 changes: 17 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"listeners": {
"*:80": {
"pass": "applications/fastapi"
}
},

"applications": {
"fastapi": {
"type": "python3",
"path": "/app/backend",
"home": "/app/backend/.venv",
"module": "main",
"callable": "app"
}
}
}
16 changes: 9 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
services:
app:
build:
dockerfile: Dockerfile
context: ./
ports:
- 8000:80
backend:
build:
context: backend
environment:
- ENV=production
- DB_USER=postgres
Expand All @@ -13,4 +11,8 @@ services:
- DB_PORT=5432
- DB_NAME=DB
- DB_SCHEMA=convoy

ui:
build:
context: ui
ports:
- 8000:80
15 changes: 15 additions & 0 deletions ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:latest as ui

WORKDIR /app/ui

COPY package*.json .
RUN npm install -g pnpm
RUN pnpm install

ADD ./ ./

RUN pnpm ng build --configuration=production --base-href /ui/ --deploy-url /ui/

FROM nginx:alpine
COPY --from=ui /app/ui/dist/ui/ /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
18 changes: 18 additions & 0 deletions ui/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 8000;
# Add here the IP address of your server
# or a domain pointing to that IP (e.g., example.com or www.example.com)
# server_name XXXX;
keepalive_timeout 5;
client_max_body_size 4G;
location /api {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;

if (!-f $request_filename) {
proxy_pass http://backend;
break;
}
}
}
4 changes: 3 additions & 1 deletion ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SupplyEditComponent } from './components/supply-edit/supply-edit.compon
import { TaskStatusBadgeComponent } from './components/task-status-badge/task-status-badge.component';
import { TaskSupplyStatusBadgeComponent } from './components/task-supply-status-badge/task-supply-status-badge.component';
import { TaskComponent } from './components/task/task.component';
import { TaskTodoistBadgeComponent } from './components/task-todoist-badge/task-todoist-badge.component';

ClarityIcons.addIcons(homeIcon, fuelIcon, tasksIcon, toolsIcon, plusCircleIcon, floppyIcon, trashIcon);
@NgModule({
Expand All @@ -46,7 +47,8 @@ ClarityIcons.addIcons(homeIcon, fuelIcon, tasksIcon, toolsIcon, plusCircleIcon,
SuppliesComponent,
SupplyEditComponent,
TaskSupplyStatusBadgeComponent,
TaskComponent
TaskComponent,
TaskTodoistBadgeComponent
],
imports: [
BrowserModule,
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/components/machines/machines.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class MachinesComponent implements OnInit {
model: '',
year: 0,
image: '',
current_meter_reading: 0
}

ngOnInit(): void {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<span *ngIf="task.todoist_task_id" class="label">
<svg xmlns="http://www.w3.org/2000/svg" class="loading_screen--logo">
<g fill="none" fill-rule="evenodd">
<path fill="#E44332" d="M56 0H8C3.6 0 0 3.6 0 8v48c0 4.4 3.6 8 8 8h48c4.4 0 8-3.6 8-8V8c0-4.4-3.6-8-8-8"
class="logo_bg" />
<g fill="#FFF" class="logo_stripe">
<path
d="M13.672 29.986c1.13-.652 25.344-14.585 25.9-14.906.554-.32.582-1.302-.038-1.656-.621-.354-1.8-1.024-2.239-1.28a2.04 2.04 0 0 0-1.995.023c-.309.178-21.002 12.077-21.694 12.47a2.7 2.7 0 0 1-2.677 0L0 18.286v5.397c2.66 1.55 9.274 5.402 10.877 6.307.957.54 1.873.527 2.795-.005" />
<path
d="M13.672 40.77c1.13-.652 25.344-14.585 25.9-14.906.554-.32.582-1.303-.038-1.657-.621-.354-1.8-1.023-2.239-1.28a2.04 2.04 0 0 0-1.995.024c-.309.178-21.002 12.076-21.694 12.47a2.7 2.7 0 0 1-2.677-.001C10.277 35.043 0 29.07 0 29.07v5.397c2.66 1.55 9.274 5.401 10.877 6.306.957.54 1.873.527 2.795-.004" />
<path
d="m13.672 51.553 25.9-14.906c.554-.32.582-1.302-.038-1.656-.621-.354-1.8-1.024-2.239-1.28a2.04 2.04 0 0 0-1.995.023c-.309.179-21.002 12.077-21.694 12.47a2.7 2.7 0 0 1-2.677 0L0 39.853v5.398c2.66 1.549 9.274 5.401 10.877 6.306.957.54 1.873.527 2.795-.005" />
</g>
</g>
</svg>
</span>
<span *ngIf="!task.todoist_task_id" style="float: right;">

</span>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { TaskTodoistBadgeComponent } from './task-todoist-badge.component';

describe('TaskTodoistBadgeComponent', () => {
let component: TaskTodoistBadgeComponent;
let fixture: ComponentFixture<TaskTodoistBadgeComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TaskTodoistBadgeComponent]
})
.compileComponents();

fixture = TestBed.createComponent(TaskTodoistBadgeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Component, Input } from '@angular/core';
import { TaskSchema } from 'src/client';

@Component({
selector: 'app-task-todoist-badge',
templateUrl: './task-todoist-badge.component.html',
styleUrl: './task-todoist-badge.component.css'
})
export class TaskTodoistBadgeComponent {
@Input() task: TaskSchema;
public class: string;
public ngOnInit() {}
}
4 changes: 3 additions & 1 deletion ui/src/app/components/task/task.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
<clr-button-group class="btn-primary btn-sm task-button-group">
<clr-button (click)="openComplete()">View Details</clr-button>
<clr-button (click)="deleteTask()">Delete</clr-button>
<clr-button (click)="syncToTodoist()">Todoist Sync</clr-button>

</clr-button-group>
</div>
<div class="card-block">
<span *ngIf="machine" class="label label-info">{{machine.year}} {{machine.make}} {{machine.model}}</span>
<app-task-status-badge [machine]="machine" [task]="task"></app-task-status-badge>
<app-task-supply-status-badge [task]="task"></app-task-supply-status-badge>

<app-task-todoist-badge [task]="task"></app-task-todoist-badge>
</div>
</div>
<clr-side-panel *ngIf="machine" [(clrSidePanelOpen)]="showComplete" [clrSidePanelStaticBackdrop]="true">
Expand Down
6 changes: 4 additions & 2 deletions ui/src/app/components/task/task.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { MachineSchema, SupplySchema, TaskCompleteSchema, TaskSchema, completeTask, deleteTask, getMachine } from 'src/client';
import { MachineSchema, SupplySchema, TaskCompleteSchema, TaskSchema, completeTask, deleteTask, getMachine, syncToTodoist } from 'src/client';

@Component({
selector: 'app-task',
Expand All @@ -25,7 +25,9 @@ export class TaskComponent implements OnInit {
this.refresh.emit();
})
}

public async syncToTodoist() {
await syncToTodoist({machineId: this.task.machine_id, taskId: this.task.id})
}
public cancel() {
this.showComplete = false;
}
Expand Down
18 changes: 8 additions & 10 deletions ui/src/app/components/tasks/tasks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,14 @@ export class TasksComponent {
return tasks.sort((a, b) => {
if (a.completed && !b.completed) return 1;
if (!a.completed && b.completed) return -1;
if (a.due_meter_ago > 0 && b.due_meter_ago <= 0) return -1;
if (b.due_meter_ago > 0 && a.due_meter_ago <= 0) return 1;
if (a.due_days_ago > 0 && b.due_days_ago <= 0) return -1;
if (b.due_days_ago > 0 && a.due_days_ago <= 0) return 1;
// if (a.task.overdue_reason && !b.task.overdue_reason) return -1;
// if (!a.task.overdue_reason && b.task.overdue_reason) return 1;
if (a.due_days_ago < b.due_days_ago) return 1;
if (a.due_days_ago > b.due_days_ago) return -1;
if (a.due_meter_ago < b.due_meter_ago) return 1;
if (a.due_meter_ago > b.due_meter_ago) return -1;
if (a.detailed_state.due_meter_ago > 0 && b.detailed_state.due_meter_ago <= 0) return -1;
if (b.detailed_state.due_meter_ago > 0 && a.detailed_state.due_meter_ago <= 0) return 1;
if (a.detailed_state.due_days_ago > 0 && b.detailed_state.due_days_ago <= 0) return -1;
if (b.detailed_state.due_days_ago > 0 && a.detailed_state.due_days_ago <= 0) return 1;
if (a.detailed_state.due_days_ago < b.detailed_state.due_days_ago) return 1;
if (a.detailed_state.due_days_ago > b.detailed_state.due_days_ago) return -1;
if (a.detailed_state.due_meter_ago < b.detailed_state.due_meter_ago) return 1;
if (a.detailed_state.due_meter_ago > b.detailed_state.due_meter_ago) return -1;
return 0;
});
}
Expand Down
46 changes: 12 additions & 34 deletions ui/src/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,12 @@ export const $MachineSchema = {
default: []
},
current_meter_reading: {
anyOf: [
{
type: 'number'
},
{
type: 'null'
}
],
title: 'Current Meter Reading',
default: 0
type: 'number',
title: 'Current Meter Reading'
}
},
type: 'object',
required: ['meter_unit', 'make', 'model', 'year'],
required: ['meter_unit', 'make', 'model', 'year', 'current_meter_reading'],
title: 'MachineSchema'
} as const;

Expand Down Expand Up @@ -529,10 +521,18 @@ export const $TaskDetailedState = {
}
],
default: 'NOT_DUE'
},
due_meter_ago: {
type: 'number',
title: 'Due Meter Ago'
},
due_days_ago: {
type: 'integer',
title: 'Due Days Ago'
}
},
type: 'object',
required: ['state'],
required: ['state', 'due_meter_ago', 'due_days_ago'],
title: 'TaskDetailedState'
} as const;

Expand Down Expand Up @@ -636,28 +636,6 @@ export const $TaskSchema = {
title: 'Task Supplies',
default: []
},
due_meter_ago: {
anyOf: [
{
type: 'number'
},
{
type: 'null'
}
],
title: 'Due Meter Ago'
},
due_days_ago: {
anyOf: [
{
type: 'integer'
},
{
type: 'null'
}
],
title: 'Due Days Ago'
},
detailed_state: {
anyOf: [
{
Expand Down
Loading

0 comments on commit 41968ac

Please sign in to comment.