Fakultas Ilmu Komputer UI

Commit f23f0f80 authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

Merge branch 'Features/CompanyVacancyApplicationList' of...

Merge branch 'Features/CompanyVacancyApplicationList' of https://gitlab.com/PPL2017csui/PPLA1 into develop
parents 25e2b756 30b6238a
......@@ -44,6 +44,7 @@ export default class VacancyPage extends React.Component {
<VacancyList
key={2}
userId={this.state.id}
status="applied"
url={`/students/${this.state.id}/applied-vacancies/`}
/>
</Pane>
......
......@@ -20,6 +20,8 @@ export default class Applicant extends React.Component {
ACCEPTED: 4,
};
static APPLICATION_STATUS_TEXT = ['Baru', 'Sudah Dibaca', 'Ditandai', 'Diterima', 'Ditolak'];
constructor(props) {
super(props);
/* istanbul ignore next */
......
......@@ -13,10 +13,12 @@ export default class Vacancy extends React.Component {
data: React.PropTypes.object.isRequired,
bookmarked: React.PropTypes.number,
status: React.PropTypes.string.isRequired,
applicationStatus: React.PropTypes.string,
};
static defaultProps = {
bookmarked: 0,
applicationStatus: '',
};
constructor(props) {
......@@ -104,6 +106,7 @@ export default class Vacancy extends React.Component {
</Grid.Row>
<Grid.Row>
{ this.generateAction() }
<p>{ this.props.applicationStatus }</p>
</Grid.Row>
</Grid.Column>
</Grid.Row>
......
import React from 'react';
import { Item, Button, Grid, Segment } from 'semantic-ui-react';
import { Item, Button, Grid } from 'semantic-ui-react';
import { Link } from 'react-router';
import Vacancy from './Vacancy';
import CompanyVacancy from './CompanyVacancy';
import Server from '../lib/Server';
import ModalAlert from '../components/ModalAlert';
import Aplicant from './../components/Applicant';
export default class VacancyList extends React.Component {
......@@ -13,10 +14,12 @@ export default class VacancyList extends React.Component {
url: React.PropTypes.string.isRequired,
userId: React.PropTypes.number.isRequired,
type: React.PropTypes.string,
status: React.PropTypes.string,
};
static defaultProps = {
type: 'student',
status: 'new',
};
constructor(props) {
......@@ -29,6 +32,7 @@ export default class VacancyList extends React.Component {
Server.get(this.props.url, false).then((data) => {
this.setState({ vacancies: data });
});
console.log(this.state.vacancies);
this.updateStatusList = this.updateStatusList.bind(this);
this.generateVacancies = this.generateVacancies.bind(this);
this.checkBookmark = this.checkBookmark.bind(this);
......@@ -45,7 +49,7 @@ export default class VacancyList extends React.Component {
checkApplied(id) {
for (let i = 0; i < this.state.appliedList.length; i += 1) {
if (id === this.state.appliedList[i].id) { return 'registered'; }
if (id === this.state.appliedList[i].vacancy.id) { return 'registered'; }
}
return 'new';
}
......@@ -55,7 +59,12 @@ export default class VacancyList extends React.Component {
this.setState({ bookmarkList: data });
});
Server.get(`/students/${this.props.userId}/applied-vacancies/`, false).then((data) => {
// console.log('hasil api:');
// console.log(data);
// console.log(data.vacancy);
this.setState({ appliedList: data });
console.log('applied list:')
console.log(this.state.appliedList);
});
}
......@@ -73,12 +82,14 @@ export default class VacancyList extends React.Component {
return this.state.vacancies.map(vacancy =>
(
<Vacancy
key={vacancy.id}
status={this.checkApplied(vacancy.id)}
bookmarked={this.checkBookmark(vacancy.id)}
data={vacancy}
key={this.props.status === 'applied' ? vacancy.vacancy.id : vacancy.id}
status={this.checkApplied(this.props.status === 'applied' ? vacancy.vacancy.id : vacancy.id)}
bookmarked={this.checkBookmark(this.props.status === 'applied' ? vacancy.vacancy.id : vacancy.id)}
data={this.props.status === 'applied' ? vacancy.vacancy : vacancy}
studentId={this.props.userId}
/>
applicationStatus= {this.props.status === 'applied' ? (vacancy.status === 4 ? 'Ditolak' :
(vacancy.status === 3 ? 'Diterima' : 'Terdaftar')) : ''}
>{console.log(this.checkApplied(this.props.status === 'applied' ? vacancy.vacancy.id : vacancy.id))}</Vacancy>
),
);
}
......
......@@ -26,3 +26,11 @@ class ApplicationStatusSerializer(serializers.ModelSerializer):
class Meta:
model = Application
fields = ['status']
class VacancyApplicationSerializer(serializers.ModelSerializer):
vacancy = VacancySerializer()
class Meta:
model = Application
fields = ['cover_letter', 'vacancy', 'status']
......@@ -10,7 +10,8 @@ from rest_framework.decorators import detail_route
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany, IsAdminOrVacancyOwner
from core.models import Student, Company
from core.models.vacancies import Vacancy, Application
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer, ApplicationStatusSerializer
from core.serializers.vacancies import VacancySerializer, ApplicationSerializer, ApplicationStatusSerializer, \
VacancyApplicationSerializer
class VacancyViewSet(viewsets.ModelViewSet):
......@@ -45,12 +46,12 @@ class ApplicationViewSet(viewsets.GenericViewSet):
def list(self, request, student_id):
"""
Get list of a student {student_id}'s application
Get list of a student {student_id}'s applications
---
"""
student = get_object_or_404(Student.objects.all(), pk=student_id)
vacancies = student.applied_vacancies
return Response(VacancySerializer(vacancies, many=True, context={'request': request}).data)
applications = Application.objects.filter(student=student)
return Response(VacancyApplicationSerializer(applications, many=True, context={'request': request}).data)
def create(self, request, student_id):
"""
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment