Skip to content
Open
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
99 changes: 99 additions & 0 deletions code/adam/javascript/lab07/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Lab07</title>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://unpkg.com/vue@3"></script>
<script src="script.js" defer></script>
<!-- <script src="https://cdn.tailwindcss.com/"></script> -->
</head>

<body style="background-color: #2f4f4f;">
<div id="app">
<h1 style="text-align:center; color: cornsilk;">Exploring Space Craft & Launches</h1>
<h3 style="text-align:center; color: cornsilk;">MiniCapstone API</h3>

<!-- <button @click="getCraft">Get First 10 Spacecraft</button> -->
<!-- <div>
<form @submit.prevent="getCraft" style="margin-top: 1rem;">
<label for="searchCraft" >Search Craft by :</label>
<select v-model="searchCraft" id="searchCraftId" required>
<option value="name">name</option>
<option value="manufacturer">manufacturer</option>
<option value="status">in-use</option>
</select>
</form>
</div> -->

<hr>
<h2 style="text-align:center; color: cornsilk;">Space Craft 🌌</h2>
<form @submit.prevent="searchKeyword" style="margin-top: 0.5rem; margin-bottom: 0.5rem">
<label for="keyword-search" style="color: cornsilk;">Enter name of space craft : </label>
<input v-model="searchTerm" type="text" id="keyword-search" placeholder="space craft" autofocus>
<input type="submit" value="Search" style="margin-left: 0.5rem">
</form>


<button @click="previousPage" v-if='previousUrl' style="margin: 0.5rem;">previous Page</button>
<button @click="nextPage" v-if='nextUrl' style="margin: 0.5rem;">next Page</button>
<div v-for="(craft,index) in spacecraft" id="craft" style="display:flex; justify-content:flex-right; width:95%; background-color: coral; margin-bottom: 0.5rem; border-radius: 20px;">
<img style="max-height: 20rem; border-radius: 20px 0px 0px 20px" v-bind:src="craft.spacecraft_config.image_url">
<ul>
<li style="margin: 0.5rem;">{{ craft.name }}</li>
<li style="margin: 0.5rem;">{{ craft.description }}</li>
<li style="margin: 0.5rem;">{{ craft.status.name }}</li>
</ul>
</div>

<div style="margin-top: 2rem; margin-bottom: 1rem;">
<hr>
<h2 style="text-align:center; color: cornsilk; margin-bottom: 2rem;">Upcoming Launches 🚀</h2>
<div style="display: flex; justify-content: center;">
<button @click="getLaunch">Upcoming Launches</button><br>
</div>
<button @click="previousPageLaunch" v-if='previousUrlLaunch' style="margin: 0.5rem;">previous Page</button>
<button @click="nextPageLaunch" v-if='nextUrlLaunch' style="margin: 0.5rem;">next Page</button>
<div v-for="(launch,index) in upcomingLaunches" id="launch" style="display:flex; justify-content:flex-right; width:95%; background-color: coral; margin-bottom: 0.5rem; border-radius: 20px;">
<img style="max-height: 20rem; border-radius: 20px 0px 0px 20px" v-bind:src="launch.image">
<ul>
<li style="margin: 0.5rem;">{{ launch.name }}</li>
<li style="margin: 0.5rem;">{{ launch.launch_service_provider.name }}</li>
<li style="margin: 0.5rem;">{{ launch.launch_service_provider.type }}</li>
<li v-if="launch.mission" style="margin: 0.5rem;">{{ launch.mission.description }}</li>
<li style="margin: 0.5rem;">{{ launch.status.name }}</li>
</ul>
</div>
</div>
<div>
<hr>
<h2 style="text-align:center; color: cornsilk;">Search Launches 🚀</h2>
<form @submit.prevent="launchSearch" style="margin-top: 0.5rem; margin-bottom: 0.5rem">
<label for="search-launch" style="color: cornsilk;">Enter search for launches :</label>
<input v-model="searchLaunch" type="text" id="search-launch" required placeholder="search">
<input type="submit" value="Search" style="margin-left: 0.5rem">
<br>
<button @click="previousPageLaunchSearch" v-if='previousUrlLaunchSearch' style="margin: 0.5rem;">previous Page</button>
<button @click="nextPageLaunchSearch" v-if='nextUrlLaunchSearch' style="margin: 0.5rem;">next Page</button>
<div v-for="(launch,index) in launchesSearched" id="launch-search" style="display:flex; justify-content:flex-right; width:95%; background-color: coral; margin-bottom: 0.5rem; border-radius: 20px;">
<img style="max-height: 20rem; border-radius: 20px 0px 0px 20px" v-bind:src="launch.image">
<ul>
<li style="margin: 0.5rem;">{{ launch.lsp_name }}</li>
<li style="margin: 0.5rem;">{{ launch.name }}</li>
<li style="margin: 0.5rem;">{{ launch.location }}</li>
<li v-if="launch.mission" style="margin: 0.5rem;">{{ launch.mission }}</li>
<li style="margin: 0.5rem;">{{ launch.status.name }}</li>
<ul>
<li style="margin: 0.5rem;">{{ launch.status.description }}</li>
</ul>
</ul>
</form>
</div>

</div>


</body>
</html>
182 changes: 182 additions & 0 deletions code/adam/javascript/lab07/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
axios({
url: 'https://lldev.thespacedevs.com/2.2.0/launch/?mode=list&search=SpaceX',
method: 'get',
headers: {
Accept: 'application/json'
}
}).then(res => {
console.log(res.data)
})

const App = {
data () {
return {
searchType: '',
searchTerm: '',
baseUrl: 'https://lldev.thespacedevs.com/2.2.0/',
spacecraft: [],
allSpacecraft: [],
searchCraft: '',
nextUrl:'',
previousUrl: '',
url: 'https://lldev.thespacedevs.com/2.2.0/spacecraft/',
limit: 10,
offset: 0, // methods that do this.offset += 10 or this.offset -= 10
upcomingLaunches: [],
upcomingLaunchesAll: [],
previousUrlLaunch: '',
previousUrlLaunchSearch: '',
nextUrlLaunch: '',
nextUrlLaunchSearch: '',
searchLaunch: '',
launchesSearched: [],
}
},

methods: {
getCraft () {
//console.log(res.data)
axios({
url: this.baseUrl + 'spacecraft/', // url: this.url,
headers: { Accept: 'application/json' },
method: 'get',
params: { status: this.searchType} //limit: 10, offset: 0
}).then(res=> {
console.log(res.data.results)
console.log(this.searchType)
this.spacecraft = res.data.results
// this.spacecraft = this.allSpacecraft[Math.floor(Math.random()*this.allspacecraft.length)]
this.nextUrl = res.data.next
console.log(res.data.next)
// this.url = res.data.next
})
},
nextPage() {
axios({
url: this.nextUrl,
headers: { Accept: 'application/json' },
method: 'get',
}).then(res=> {
this.spacecraft = res.data.results
this.nextUrl = res.data.next
this.previousUrl = res.data.previous
// this.nextUrlLaunch = res.data.next
console.log(res.data)
console.log('nextUrl '+this.nextUrl)
console.log('previousUrl '+this.previousUrl)
})
},
previousPage() {
axios({
url: this.previousUrl,
method: 'get',
headers: { Accept: 'application/json' },
}).then(res=> {
this.spacecraft = res.data.results
this.nextUrl = res.data.next
// this.previousUrl = res.data.previous
console.log(res.data)
console.log(res.data.next)
})
},
searchKeyword() {
axios({
url: this.baseUrl + 'spacecraft/',
headers: { Accept: 'application/json' },
params: { search: this.searchTerm, status: this.searchType },
method: 'get',
}).then(res=> {
console.log(res.data)
this.spacecraft = res.data.results
this.nextUrl = res.data.next
this.previousUrl = res.data.previous
})
},

launchSearch() {
axios({
url: 'https://lldev.thespacedevs.com/2.2.0/launch/?mode=list&search=' + this.launchSearch,
headers: { Accept: 'application/json' },
params: { search: this.searchLaunch },
method: 'get',
}).then(res=> {
console.log(this.searchLaunch)
console.log(res.data)
this.launchesSearched = res.data.results
this.nextUrlLaunchSearch = res.data.next
this.previousUrlLaunchSearch = res.data.previous
console.log(this.nextUrlLaunchSearch)
})
},

getLaunch() {
axios({
url: 'https://lldev.thespacedevs.com/2.2.0/launch/upcoming',
headers: { Accept: 'application/json'},
method: 'get',
}).then(res=> {
this.nextUrlLaunch = res.data.next
this.previousUrlLaunch = res.data.previous
this.upcomingLaunches = res.data.results
})
},

nextPageLaunch() {
axios({
url: this.nextUrlLaunch,
headers: { Accept: 'application/json' },
method: 'get',
}).then(res=> {
this.upcomingLaunches = res.data.results
this.nextUrlLaunch = res.data.next
this.previousUrlLaunch = res.data.previous
console.log(res.data)
})
},

previousPageLaunch() {
axios({
url: this.previousUrlLaunch,
method: 'get',
headers: { Accept: 'application/json' },
}).then(res=> {
this.upcomingLaunches = res.data.results
this.nextUrlLaunch = res.data.next
this.previousUrlLaunch = res.data.previous
console.log(res.data)
console.log(res.data.next)
})
},

nextPageLaunchSearch() {
axios({
url: this.nextUrlLaunchSearch,
headers: { Accept: 'application/json' },
method: 'get',
}).then(res=> {
this.launchesSearched = res.data.results
this.nextUrlLaunchSearch = res.data.next
this.previousUrlLaunchSearch = res.data.previous
console.log(res.data)
})
},

previousPageLaunchSearch() {
axios({
url: this.previousUrlLaunchSearch,
method: 'get',
headers: { Accept: 'application/json' },
}).then(res=> {
this.launchesSearched = res.data.results
this.nextUrlLaunchSearch = res.data.next
this.previousUrlLaunchSearch = res.data.previous
console.log(res.data)
console.log(res.data.next)
})
},

}
}

const app = Vue.createApp(App)
app.mount('#app')