Skip to content
Closed
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
37 changes: 6 additions & 31 deletions src/app/pages/AddAppPage/components/add-app/add-app.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,9 @@



// .add-app {
// padding-top: 80px;
// .header {
// text-align: center;
// h2 {
// padding: 10px;
// margin: 20px 0;
// display: inline-block;
// }


// }
// .form-actions {
// .btn {
// background: $primary;
// color: $white;
// }
// }
// .ng-valid[required] {
// border-left: 5px solid #42A948; /* green */
// }

// .ng-invalid {
// border-left: 5px solid #a94442; /* red */
// }
// .custom-messages {
// h3 {
// padding: 15px;
// }
// }
// }
.add-app {
.custom-messages .alert {
padding-top: 10px;
padding-bottom: 10px;
}
}
42 changes: 37 additions & 5 deletions src/app/pages/AddAppPage/components/add-app/add-app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {CivicFile} from '../../../../shared/models/civic-file.model';
import {UploadService} from '../../../../services/upload.service';
import {Component, OnInit, Input, OnChanges, SimpleChanges} from '@angular/core';
import {Component, OnInit, Input, OnChanges, SimpleChanges, ViewChild, ElementRef} from '@angular/core';

import {AppService} from '../../../../services/app.service';
import {CategoriesService} from '../../../../services/category.service';
Expand All @@ -26,6 +26,7 @@ export class AddAppComponent implements OnInit, OnChanges {
constructor(private appService: AppService, private tagsService: TagsService, private technologiesService: TechnologiesService, private categoriesService: CategoriesService, private uploadService: UploadService) {

this.submitted = false;
this.successful = false;
this.isAddingNewApp = true;
}

Expand All @@ -41,6 +42,7 @@ export class AddAppComponent implements OnInit, OnChanges {
public selectedTechnologies: string[] = [];
private newTag: string;
private submitted: boolean;
private successful: boolean;
private message;
private error;
private appLogo: CivicFile;
Expand All @@ -53,6 +55,9 @@ export class AddAppComponent implements OnInit, OnChanges {
private needsToUpdateNgoLogo: boolean;
public phoneRegex = '\\+4\\d{10}';

@ViewChild('appLogoInput') appLogoInputRef: ElementRef;
@ViewChild('ngoLogoInput') ngoLogoInputRef: ElementRef;

ngOnChanges(changes: SimpleChanges) {
if (changes['app']) {
this.submitted = false;
Expand Down Expand Up @@ -177,7 +182,7 @@ export class AddAppComponent implements OnInit, OnChanges {
this.isNgoLogoUploaded = false;
}
this.error = err.toString();
}
}

addApp(form) {
if (this.isAddingNewApp) {
Expand Down Expand Up @@ -237,19 +242,19 @@ export class AddAppComponent implements OnInit, OnChanges {
if (this.message === 'success') {
this.error = null;
this.setDefaultsForLogoWhenEditingApp();

} else {
const errorRegex = /\(ERROR\)\:(.*)/;
this.error = errorRegex.exec(this.message);
}

AddAppComponent.scrollToTop();
}
}
});
}
}

private addNewApp(form) {
this.successful = false;
this.submitted = true;

if (this.isAppLogoValid && this.isNgoLogoValid) {
Expand All @@ -273,22 +278,33 @@ export class AddAppComponent implements OnInit, OnChanges {

this.message = response['result'];
if (this.message === 'success') {
this.submitted = false;
this.successful = true;
this.error = null;
this.setDefaultsForLogoRelated();
form.reset();
this.setFormDefaults();
} else {
const errorRegex = /\(ERROR\):(.*)/;
this.error = errorRegex.exec(this.message)[1];
}
AddAppComponent.scrollToTop();
}
}

});
} else {
this.error = 'Logo-ul aplicației sau al organizației este invalid, poate sa fie doar .png sau .jpg, maxim 500px x 500px.';
AddAppComponent.scrollToTop();
}
}

private setDefaultsForLogoRelated() {
if (this.appLogoInputRef) {
this.appLogoInputRef.nativeElement.value = null;
}
if (this.ngoLogoInputRef) {
this.ngoLogoInputRef.nativeElement.value = null;
}
this.ngoLogo = null;
this.appLogo = null;
this.isAppLogoUploaded = false;
Expand All @@ -306,4 +322,20 @@ export class AddAppComponent implements OnInit, OnChanges {
this.needsToUpdateNgoLogo = false;

}

private setFormDefaults() {
this.setDefaultsForLogoRelated();
this.selectedAppTags = [];
this.selectedTechnologies = [];
}

private static scrollToTop() {
(function scrollSmoothly() {
const currentScroll = document.documentElement.scrollTop || document.body.scrollTop;
if (currentScroll > 0) {
window.requestAnimationFrame(scrollSmoothly);
window.scrollTo(0, currentScroll - (currentScroll / 8));
}
})();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little bit hacky. can you use scrollIntoView instead? there's neat example in approve-app.component (line 85) that method could be extracted overall and used anywhere we need it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@y0rg1 can you please check? thanks 😄

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lrdTnc I'm not entirely sure how to implement this cleanly using scrollIntoView because the navbar component (or any other top page component) is outside add-app's hierarchy.
I went with this approach in order to enable smooth scrolling on Edge and IE browsers as well.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ <h1>Adaugă-ți aplicația in Centru Civic</h1>

<div class="col-xs-12 col-md-offset-1 col-md-10">
<div class="custom-messages col-xs-12">
<div class="sucess" *ngIf="submitted && message =='success' && !error && isAddingNewApp">
<h3>Aplicația ta a fost adaugată cu succes!</h3>
<p>Te vom contacta când aceasta este publicată pe site. Mulțumim!</p>
<div class="alert alert-success" *ngIf="successful && message =='success' && !error && isAddingNewApp">
<b>Aplicația ta a fost adaugată cu succes! Te vom contacta când aceasta este publicată pe site. Mulțumim!</b>
</div>

<div class="sucess" *ngIf="submitted && message =='success' && !error && !isAddingNewApp">
<h3>Aplicația a fost modificată cu succes!</h3>

<div class="alert alert-success" *ngIf="submitted && message =='success' && !error && !isAddingNewApp">
<b>Aplicația a fost modificată cu succes!</b>
</div>

<div class="alert alert-danger" *ngIf="submitted && error">
{{error}}
<b>{{error}}</b>
</div>
</div>
<form #form="ngForm" (ngSubmit)="addApp(form)" novalidate name="addAppForm">
Expand Down Expand Up @@ -116,7 +114,7 @@ <h3>Aplicația a fost modificată cu succes!</h3>

<div class="form-group">
<label>Logo-ul aplicației <span class="req">*</span></label>
<input type="file" class="form-control" accept=".jpg,.png,image/png,image/jpeg,image/jpg" (change)="appLogoChangeEvent($event)"
<input #appLogoInput type="file" class="form-control" accept=".jpg,.png,image/png,image/jpeg,image/jpg" (change)="appLogoChangeEvent($event)"
placeholder="" />
<span class="help-block">Logo-ul aplicației poate să fie doar <code>.png</code> sau <code>.jpg</code>, maxim <code>500px x 500px</code>.</span>
<div *ngIf="!isAddingNewApp" class="card-image">
Expand Down Expand Up @@ -242,7 +240,7 @@ <h3>Aplicația a fost modificată cu succes!</h3>

<div class="form-group">
<label>Logo-ul tău</label>
<input type="file" class="form-control" accept=".jpg,.png,image/png,image/jpeg,image/jpg" (change)="ngoLogoChangeEvent($event)"
<input #ngoLogoInput type="file" class="form-control" accept=".jpg,.png,image/png,image/jpeg,image/jpg" (change)="ngoLogoChangeEvent($event)"
placeholder="" />
<span class="help-block">Logo-ul tău poate să fie doar <code>.png</code> sau <code>.jpg</code>, maxim <code>500px x 500px</code>.</span>
<div *ngIf="!isAddingNewApp" class="media-left media-middle">
Expand Down