Skip to content

Commit

Permalink
Assignment update done
Browse files Browse the repository at this point in the history
  • Loading branch information
latifedag committed Sep 9, 2023
1 parent 910f32a commit a7da5c9
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 25 deletions.
24 changes: 20 additions & 4 deletions vre-panel/pages/assignments/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,27 @@ const AssDetails: React.FC<AssDetailsProps> = ({ token }) => {
title: "Loading ..",
slug: "",
description: "Loading ..",
endpoint: "",
vlab_slug: "",
vlab : 0,
long_description: ""
}
const StudentPlaceholder = {
keycloak_ID: "Loading ..",
name: "",
assignments_enrolled: "",
}
const vlabPlaceholder = {
title: "Loading ..",
slug: "",
description: "Loading ..",
endpoint: ""
}

// const isAuthenticated = useAuth(true);
const router = useRouter();
const { slug } = router.query;
const [Ass, setAss] = useState(AssPlaceholder)
const [Stud, setStud] = useState(StudentPlaceholder)
const [vlab, setVlab] = useState(vlabPlaceholder)
var [isEnrolled, setEnrolled] = useState(false)
const session = useSession();
var userName = "none";
Expand All @@ -58,7 +64,17 @@ const AssDetails: React.FC<AssDetailsProps> = ({ token }) => {
.then((res) => res.json())
.then((data) => {
setAss(data)
})
const url = new URL("http://localhost:8000/api/vlabs/");
fetch(`${url}`)
.then((res) => res.json())
.then((data) => {
console.log(data[Ass.vlab])
setVlab(data[Ass.vlab])
})
.catch((error) => {
console.log('Featching error:'+error)
});
})
.catch((error) => {
console.log('Featching error:'+error)
});
Expand Down Expand Up @@ -151,7 +167,7 @@ const AssDetails: React.FC<AssDetailsProps> = ({ token }) => {
<div className="grid grid-flow-row-dense grid-cols-1 grid-rows-1 gap-4 p-5 min-h-screen mx-auto bg-gradient-to-b from-sky-100 to-orange-300">
<div className="row-span-4 col-span-2 shadow-lg bg-white p-10">
<p className="text-4xl font-sans">{Ass.title}</p>
<a target="blank" href= {'../vlabs/' + Ass.vlab_slug}>
<a target="blank" href= {'../vlabs/' + vlab.slug}>
<button className="bg-blue-400 hover:bg-blue-500 text-white font-bold py-2 px-4 rounded mt-5">
Go to Vlab
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 4.0.10 on 2023-09-09 18:12

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('virtual_labs', '0004_remove_virtuallab_profiles_and_more'),
('assignments', '0007_assignment_long_description'),
]

operations = [
migrations.RenameField(
model_name='assignment',
old_name='description',
new_name='short_description',
),
migrations.RemoveField(
model_name='assignment',
name='base_url',
),
migrations.RemoveField(
model_name='assignment',
name='display_name',
),
migrations.RemoveField(
model_name='assignment',
name='fqdn',
),
migrations.RemoveField(
model_name='assignment',
name='ingress_ssl_port',
),
migrations.AddField(
model_name='assignment',
name='vlab',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='virtual_labs.virtuallab'),
),
]
17 changes: 17 additions & 0 deletions vreapis/assignments/migrations/0009_remove_assignment_vlab_slug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.0.10 on 2023-09-09 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('assignments', '0008_rename_description_assignment_short_description_and_more'),
]

operations = [
migrations.RemoveField(
model_name='assignment',
name='vlab_slug',
),
]
9 changes: 3 additions & 6 deletions vreapis/assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ class Assignment(models.Model):
created = models.DateTimeField(auto_now_add=True, null=True)
title = models.CharField(max_length=100)
slug = models.SlugField(null=True, unique=True)
description = models.CharField(max_length=1000)
base_url = models.CharField(max_length=100, null=True)
fqdn = models.CharField(max_length=100, null=True)
ingress_ssl_port = models.CharField(max_length=5, null=True)
display_name = models.CharField(max_length=100, null=True)
vlab_slug = models.CharField(max_length=100, null=True)
short_description = models.CharField(max_length=1000)
long_description = models.CharField(max_length=10000, null=True)
vlab = models.ForeignKey('virtual_labs.VirtualLab', on_delete=models.CASCADE, null=True)



def __str__(self):
Expand Down
19 changes: 4 additions & 15 deletions vreapis/assignments/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,28 @@ class Meta:

class AssignmentSerializer(serializers.ModelSerializer):

endpoint = serializers.SerializerMethodField()

def get_endpoint(self, vlab):
return f"https://{vlab.fqdn}:{vlab.ingress_ssl_port}/{vlab.base_url}/"

class Meta:
model = Assignment
fields = (
'title',
'slug',
'description',
'endpoint',
'vlab_slug',
'short_description',
'vlab'

)


class AssignmentDetailSerializer(serializers.ModelSerializer):

endpoint = serializers.SerializerMethodField()

def get_endpoint(self, vlab):
return f"https://{vlab.fqdn}:{vlab.ingress_ssl_port}/{vlab.base_url}/"

class Meta:
model = Assignment
fields = (
'title',
'slug',
'description',
'endpoint',
'vlab_slug',
'short_description',
'long_description',
'vlab'
)


0 comments on commit a7da5c9

Please sign in to comment.