Last active
May 28, 2021 12:39
-
-
Save NullVoxPopuli/b1e5c105a78ad814e2204119bdeeead4 to your computer and use it in GitHub Desktop.
Convert to derived data - Original
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Component from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
export default class MyRepository extends Component { | |
@tracked showDetailVisible = false; | |
@tracked branches = ''; | |
@action | |
async showDetail(name, organizationName, token) { | |
let requestOptions = { | |
method: 'GET', | |
headers: { | |
'Accept': 'application/vnd.github.v3+json', | |
'Authorization': 'token ' + token | |
} | |
}; | |
let response = await fetch('https://api.github.com/repos/'+organizationName+'/'+name+'/branches', requestOptions); | |
let data = await response.json(); | |
if (!response.ok) { | |
this.requestError = 'Some of the properties are wrong.'; | |
} else { | |
this.branches = data; | |
this.showDetailVisible = !this.showDetailVisible; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Controller from '@ember/controller'; | |
import { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
import { filterBy } from '@ember/object/computed'; | |
export default class ApplicationController extends Controller { | |
@tracked requestError = ''; | |
@tracked dataFetched = false; | |
@tracked repositories = ''; | |
@tracked filteredRepositories = ''; | |
@tracked languages = ''; | |
@tracked isPrivate = false; | |
@tracked languageFilter = ''; | |
@action | |
isPrivateCheck(event) { | |
this.isPrivate = event.target.checked; | |
if (this.languageFilter != 'All') { | |
this.filteredRepositories = this.repositories.filterBy('private', this.isPrivate).filterBy('language', this.languageFilter); | |
} else { | |
this.filteredRepositories = this.repositories.filterBy('private', this.isPrivate) | |
} | |
} | |
@action | |
languageFilterCheck(value) { | |
this.languageFilter = value; | |
if (value != 'All') { | |
this.filteredRepositories = this.repositories.filterBy('language', value).filterBy('private', this.isPrivate); | |
} else { | |
this.filteredRepositories = this.repositories.filterBy('private', this.isPrivate); | |
} | |
} | |
@action | |
async submitToken() { | |
let requestOptions = { | |
method: 'GET', | |
headers: { | |
'Accept': 'application/vnd.github.v3+json', | |
'Authorization': 'token ' + this.token | |
} | |
}; | |
this.requestError = ''; | |
let response = await fetch('https://api.github.com/orgs/'+this.organizationName+'/repos', requestOptions); | |
let repositories = await response.json(); | |
if (!response.ok) { | |
this.requestError = 'Token or organization name is invalid.'; | |
} else { | |
let data = await Promise.all(repositories.map(async (entry) => { | |
console.log(name); | |
let response = await fetch('https://api.github.com/repos/'+this.organizationName+'/'+entry.name+'/branches', requestOptions); | |
return await response.json(); | |
})); | |
data.forEach(function(entry, index) { | |
repositories[index].branch_count = entry.length; | |
}); | |
console.log(repositories); | |
this.repositories = repositories; | |
this.filteredRepositories = repositories; | |
this.dataFetched = true; | |
let dropdownLanguages = [...new Set(repositories.map(a => a.language))]; | |
let removedNullFromLanguages = dropdownLanguages.filter(function (e) {return e != null;}); | |
let allFilter = 'All'; | |
let addAllFilter = [allFilter].concat(removedNullFromLanguages); | |
this.languages = addAllFilter; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment