Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Wandering-Cursor/Samurai-Frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Artem Smotrych committed Jun 3, 2024
2 parents 1f3c0e4 + 0c2b9bb commit be1ce86
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 187 deletions.
54 changes: 11 additions & 43 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@amcharts/amcharts5": "^5.5.7",
"@amcharts/amcharts5-geodata": "^5.1.1",
"@angular-slider/ngx-slider": "^2.0.4",
"@angular-slider/ngx-slider": "^17.0.0",
"@angular/animations": "^17.0.4",
"@angular/cdk": "^17.0.1",
"@angular/common": "^17.0.4",
Expand Down Expand Up @@ -71,7 +71,6 @@
"ngx-pipes": "^3.2.2",
"ngx-quill": "^25.3.2",
"ngx-slick-carousel": "^17.0.0",
"ngx-slider-v2": "^17.0.0",
"ngx-spinner": "^16.0.2",
"ngx-toastr": "^18.0.0",
"ngx-ui-switch": "^15.0.0",
Expand Down Expand Up @@ -105,4 +104,4 @@
"overrides": {
"autoprefixer": "10.4.16"
}
}
}
169 changes: 78 additions & 91 deletions src/app/core/services/rest-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const httpOptions = {
providedIn: 'root',
})
export class restApiService {
constructor(private http: HttpClient) {}
constructor(private http: HttpClient) { }

/**
* Product Rest Api
Expand Down Expand Up @@ -95,7 +95,7 @@ this.restApiService.getProjectTasks(projectId, { page: 1, page_size: 10 }, 'task
}

return this.http.get(
`${GlobalComponent.API_URL}/projects/tasks/${projectId}`,
`${GlobalComponent.API_URL}projects/tasks/${projectId}`,
{ params }
);
}
Expand All @@ -116,7 +116,7 @@ this.restApiService.getProjectTasks(projectId, { page: 1, page_size: 10 }, 'task
}

updateTaskStatus(taskId: string, status: string): Observable<any> {
return this.http.put(`${GlobalComponent.API_URL}projects/task/${taskId}/status`, { status });
return this.http.put(`${GlobalComponent.API_URL}projects/task/${taskId}/status`, { state: status });
}

postComment(taskId: string, comment: any): Observable<any> {
Expand All @@ -134,35 +134,35 @@ this.restApiService.getProjectTasks(projectId, { page: 1, page_size: 10 }, 'task
return this.http.put(`${GlobalComponent.API_URL}projects/comments/${commentId}`, comment);
}

// In your service
// In your service
postFile(fileData: FormData): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}common/file`, fileData);
}


downloadFile(fileId: string): Observable<{blob: Blob, filename: string}> {
return this.http.get(`${GlobalComponent.API_URL}common/file/${fileId}`, {
responseType: 'blob',
observe: 'response'
}).pipe(
map((response: HttpResponse<Blob>) => {
// Log all response headers
const headers = response.headers.keys();
headers.forEach(header => console.log(`${header}: ${response.headers.get(header)}`));

const contentDisposition = response.headers.get('Content-Disposition') || '';
console.log('Content-Disposition header:', contentDisposition);
downloadFile(fileId: string): Observable<{ blob: Blob, filename: string }> {
return this.http.get(`${GlobalComponent.API_URL}common/file/${fileId}`, {
responseType: 'blob',
observe: 'response'
}).pipe(
map((response: HttpResponse<Blob>) => {
// Log all response headers
const headers = response.headers.keys();
headers.forEach(header => console.log(`${header}: ${response.headers.get(header)}`));

const matches = /filename\s*=\s*(?:"([^"]*)"|([^;]*))/i.exec(contentDisposition);
console.log('Regex matches:', matches);
const contentDisposition = response.headers.get('Content-Disposition') || '';
console.log('Content-Disposition header:', contentDisposition);

const filename = matches && (matches[1] || matches[2]) ? matches[1] || matches[2] : 'default-filename.ext';
console.log('Extracted filename:', filename);
const matches = /filename\s*=\s*(?:"([^"]*)"|([^;]*))/i.exec(contentDisposition);
console.log('Regex matches:', matches);

return { blob: response.body as Blob, filename };
})
);
}
const filename = matches && (matches[1] || matches[2]) ? matches[1] || matches[2] : 'default-filename.ext';
console.log('Extracted filename:', filename);

return { blob: response.body as Blob, filename };
})
);
}



Expand All @@ -171,75 +171,62 @@ downloadFile(fileId: string): Observable<{blob: Blob, filename: string}> {
return this.http.get<FileInfo>(`${GlobalComponent.API_URL}common/file/${fileId}/info`);
}

createChat(chatData: ChatCreateRequest): Observable<ChatRepresentation> {
return this.http.post<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat`, chatData);
// Create a new chat
createChat(chatData: any): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat`, chatData);
}

getChats(page: number = 1, pageSize: number = 10, name?: string): Observable<ChatRepresentation[]> {
let queryParams = `?page=${page}&page_size=${pageSize}`;
if (name) {
queryParams += `&name=${encodeURIComponent(name)}`;
}
return this.http.get<ChatSearchResponse>(`${GlobalComponent.API_URL}communication/chat${queryParams}`).pipe(
map(response => response.content)
);

// Get all chats
getChats(): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/chat`);
}

// Get specific chat by ID
getChat(chatId: string): Observable<any> {
return this.http.get(`${GlobalComponent.API_URL}communication/chat/${chatId}`);
}

// Update specific chat
updateChat(chatId: string, updateData: any): Observable<any> {
return this.http.patch(`${GlobalComponent.API_URL}communication/chat/${chatId}`, updateData);
}

// Add member to chat
addChatMember(chatId: string, userId: string): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat/${chatId}/add_member`, { userId });
}

// Leave a chat
leaveChat(chatId: string): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/chat/${chatId}/leave`, {});
}

// Get chat participants
getChatParticipants(chatId: string): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/chat/${chatId}/participants`);
}

// Messaging services
createMessage(messageData: any): Observable<any> {
return this.http.post(`${GlobalComponent.API_URL}communication/message`, messageData);
}

getMessage(messageId: string): Observable<any> {
return this.http.get(`${GlobalComponent.API_URL}communication/message/${messageId}`);
}

updateMessage(messageId: string, messageData: any): Observable<any> {
return this.http.put(`${GlobalComponent.API_URL}communication/message/${messageId}`, messageData);
}

markMessageSeen(messageId: string): Observable<any> {
return this.http.patch(`${GlobalComponent.API_URL}communication/message/${messageId}/seen`, {});
}

// Get who has seen the message
getMessageSeenBy(messageId: string): Observable<any[]> {
return this.http.get<any[]>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen_by`);
}

// Get specific chat by ID
getChat(chatId: string): Observable<ChatRepresentation> {
return this.http.get<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}`);
}

// Update specific chat
updateChat(chatId: string, updateData: ChatUpdateRequest): Observable<ChatRepresentation> {
return this.http.patch<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}`, updateData);
}

// Add member to chat
addChatMember(chatId: string, accountIds: string[]): Observable<ChatRepresentation> {
const requestData: ChatAddMemberRequest = { account_ids: accountIds };
return this.http.post<ChatRepresentation>(`${GlobalComponent.API_URL}communication/chat/${chatId}/add_member`, requestData);
}

// Leave a chat
leaveChat(chatId: string): Observable<ChatLeaveResponse> {
return this.http.post<ChatLeaveResponse>(`${GlobalComponent.API_URL}communication/chat/${chatId}/leave`, {});
}

// Get chat participants
getChatParticipants(chatId: string, page: number = 1, pageSize: number = 10, name?: string): Observable<ChatParticipantsResponse> {
let params = new HttpParams()
.set('page', page.toString())
.set('page_size', pageSize.toString());

if (name) {
params = params.set('name', name);
}

return this.http.get<ChatParticipantsResponse>(`${GlobalComponent.API_URL}communication/chat/${chatId}/participants`, { params });
}

// Messaging services
createMessage(messageData: MessageCreateRequest): Observable<MessageRepresentation> {
return this.http.post<MessageRepresentation>(`${GlobalComponent.API_URL}communication/message`, messageData);
}

getMessage(messageId: string): Observable<MessageRepresentation> {
return this.http.get<MessageRepresentation>(`${GlobalComponent.API_URL}communication/message/${messageId}`);
}

updateMessage(messageId: string, messageData: any): Observable<any> {
return this.http.put(`${GlobalComponent.API_URL}communication/message/${messageId}`, messageData);
}

markMessageSeen(messageId: string): Observable<void> {
return this.http.patch<void>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen`, {});
}

// Get who has seen the message
getMessageSeenBy(messageId: string): Observable<MessageSeenByResponse> {
return this.http.get<MessageSeenByResponse>(`${GlobalComponent.API_URL}communication/message/${messageId}/seen_by`);
}

// Delete
deleteData(id: any): Observable<any> {
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/ecommerce/ecommerce.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { NgSelectModule } from '@ng-select/ng-select';
import { CountUpModule } from 'ngx-countup';

// Range Slider
import { NgxSliderModule } from 'ngx-slider-v2';
import { NgxSliderModule } from '@angular-slider/ngx-slider';

// Swiper Slider
import { SlickCarouselModule } from 'ngx-slick-carousel';
Expand Down
10 changes: 5 additions & 5 deletions src/app/pages/forms/forms.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { UiSwitchModule } from 'ngx-ui-switch';
import { TimepickerModule } from 'ngx-bootstrap/timepicker';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { NgxSliderModule } from 'ngx-slider-v2';
import { NgxSliderModule } from '@angular-slider/ngx-slider';

// Color Picker
import { ColorPickerModule } from 'ngx-color-picker';
Expand Down Expand Up @@ -60,10 +60,10 @@ import { LayoutComponent } from './layout/layout.component';

const DEFAULT_DROPZONE_CONFIG: DropzoneConfigInterface = {
// Change this to your upload POST address:
url: 'https://httpbin.org/post',
maxFilesize: 50,
acceptedFiles: 'image/*'
};
url: 'https://httpbin.org/post',
maxFilesize: 50,
acceptedFiles: 'image/*'
};

@NgModule({
declarations: [
Expand Down
2 changes: 1 addition & 1 deletion src/app/pages/learning/courses/courses.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SharedModule } from 'src/app/shared/shared.module';
import { NgSelectModule } from '@ng-select/ng-select';

// Range Slider
import { NgxSliderModule } from 'ngx-slider-v2';
import { NgxSliderModule } from '@angular-slider/ngx-slider';

//Wizard
import { CdkStepperModule } from '@angular/cdk/stepper';
Expand Down
Loading

0 comments on commit be1ce86

Please sign in to comment.