-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3444 from fjordllc/bug/subscription-status
サブスクステータスの表示を非同期化
- Loading branch information
Showing
12 changed files
with
244 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class API::SubscriptionsController < API::BaseController | ||
def index | ||
@subscriptions = Subscription.new.all | ||
end | ||
end |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const statusMap = { | ||
trialing: 'is-primary', | ||
active: 'is-success', | ||
canceled: 'is-danger', | ||
past_due: 'is-warning' | ||
} | ||
const statusLabel = { | ||
trialing: 'お試し中', | ||
active: '有効', | ||
canceled: 'キャンセル', | ||
past_due: '期日経過' | ||
} | ||
const selector = '.subscription-status' | ||
const statuses = document.querySelectorAll(selector) | ||
if (statuses) { | ||
let subs = [] | ||
|
||
fetch('/api/subscriptions.json', { | ||
method: 'GET', | ||
headers: { 'X-Requested-With': 'XMLHttpRequest' }, | ||
credentials: 'same-origin', | ||
redirect: 'manual' | ||
}) | ||
.then((response) => { | ||
return response.json() | ||
}) | ||
.then((json) => { | ||
subs = json.subscriptions | ||
|
||
statuses.forEach((status) => { | ||
const subId = status.getAttribute('data-subscription-id') | ||
subs.forEach((sub) => { | ||
if (sub.id === subId) { | ||
const level = statusMap[sub.status] | ||
const label = statusLabel[sub.status] | ||
status.classList.add('a-button') | ||
status.classList.add('is-sm') | ||
status.classList.add(level) | ||
status.innerHTML = label | ||
} | ||
}) | ||
}) | ||
}) | ||
.catch((error) => { | ||
console.warn('Failed to parsing', error) | ||
}) | ||
} | ||
}) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
json.subscriptions do | ||
json.array! @subscriptions do |subscription| | ||
json.id subscription['id'] | ||
json.status subscription['status'] | ||
end | ||
end |
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
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class API::SubscriptionsTest < ActionDispatch::IntegrationTest | ||
test 'GET /api/subscriptions.json' do | ||
get api_subscriptions_path(format: :json) | ||
assert_response :unauthorized | ||
|
||
token = create_token('hatsuno', 'testtest') | ||
VCR.use_cassette 'subscription/all' do | ||
get api_subscriptions_path(format: :json), | ||
headers: { 'Authorization' => "Bearer #{token}" } | ||
end | ||
|
||
id = JSON.parse(@response.body)['subscriptions'][0]['id'] | ||
assert_equal users(:hatsuno).subscription_id, id | ||
end | ||
end |
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
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