Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unread counter to console tab button. #995

Merged
merged 2 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
75 changes: 43 additions & 32 deletions lib/experimental/new_embed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class NewEmbed {
TabView testTabView;
ConsoleTabView consoleTabView;

Counter unreadConsoleCounter;

FlashBox testResultBox;
FlashBox analysisResultBox;

Expand Down Expand Up @@ -67,16 +69,19 @@ class NewEmbed {
if (name == 'editor') {
userCodeEditor.resize();
userCodeEditor.focus();
}

if (name == 'test') {
} else if (name == 'test') {
testEditor.resize();
testEditor.focus();
} else {
// Must be the console tab.
unreadConsoleCounter.clear();
}
}),
);
}

unreadConsoleCounter = Counter(querySelector('#unread-console-counter'));

executeButton =
ExecuteCodeButton(querySelector('#execute'), _handleExecute);

Expand Down Expand Up @@ -110,8 +115,21 @@ class NewEmbed {
consoleTabView = ConsoleTabView(DElement(querySelector('#console-view')));

executionSvc = ExecutionServiceIFrame(querySelector('#frame'));
executionSvc.onStderr.listen((err) => consoleTabView.appendError(err));
executionSvc.onStdout.listen((msg) => consoleTabView.appendMessage(msg));

executionSvc.onStderr.listen((err) {
if (tabController.selectedTab.name != 'console') {
unreadConsoleCounter.increment();
}
consoleTabView.appendError(err);
});

executionSvc.onStdout.listen((msg) {
if (tabController.selectedTab.name != 'console') {
unreadConsoleCounter.increment();
}
consoleTabView.appendMessage(msg);
});

executionSvc.testResults.listen((result) {
if (result.success) {
executeButton.executionState = ExecutionState.testSuccess;
Expand Down Expand Up @@ -178,15 +196,13 @@ class NewEmbed {
.compile(input)
.timeout(longServiceCallTimeout)
.then((CompileResponse response) {
executionSvc.execute('', '', response.result);
})
.catchError((e) {
consoleTabView.appendError('Error compiling to JavaScript:\n$e');
tabController.selectTab('console');
})
.whenComplete(() {
executeButton.executionState = ExecutionState.ready;
});
executionSvc.execute('', '', response.result);
}).catchError((e) {
consoleTabView.appendError('Error compiling to JavaScript:\n$e');
tabController.selectTab('console');
}).whenComplete(() {
executeButton.executionState = ExecutionState.ready;
});
}

void _displayIssues(List<AnalysisIssue> issues) {
Expand Down Expand Up @@ -316,27 +332,22 @@ class ConsoleTabView extends TabView {
}
}

/// A line of text next to the [ExecuteButton] that reports test result messages
/// in red or green.
class TestResultLabel {
TestResultLabel(this.element);
class Counter {
Counter(this.element);

final DivElement element;
final SpanElement element;

void setResult(TestResult result) {
if (result.messages.isEmpty) {
element.text = result.success ? 'Test passed!' : 'Test failed.';
} else {
element.text = result.messages.first;
}
int _itemCount = 0;

if (result.success) {
element.classes.add('text-green');
element.classes.remove('text-red');
} else {
element.classes.remove('text-green');
element.classes.add('text-red');
}
void increment() {
_itemCount++;
element.text = '$_itemCount';
element.attributes.remove('hidden');
}

void clear() {
_itemCount = 0;
element.setAttribute('hidden', 'true');
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/experimental/new_embed_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@
<div class="BtnGroup mr-2">
<button id="editor-tab" class="btn BtnGroup-item selected" selected type="button">Your code</button>
<button id="test-tab" class="btn BtnGroup-item" type="button">Test</button>
<button id="console-tab" class="btn BtnGroup-item" type="button">Console</button>
<button id="console-tab" class="btn BtnGroup-item" type="button">
Console
<span id="unread-console-counter" class="Counter" hidden></span>
</button>
</div>
</div>
<div class="UnderlineNav-actions">
Expand Down Expand Up @@ -87,4 +90,3 @@
</body>

</html>

5 changes: 4 additions & 1 deletion web/experimental/embed-new.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@
<div class="BtnGroup mr-2">
<button id="editor-tab" class="btn BtnGroup-item selected" selected type="button">Your code</button>
<button id="test-tab" class="btn BtnGroup-item" type="button">Test</button>
<button id="console-tab" class="btn BtnGroup-item" type="button">Console</button>
<button id="console-tab" class="btn BtnGroup-item" type="button">
Console
<span id="unread-console-counter" class="Counter" hidden></span>
</button>
</div>
</div>
<div class="UnderlineNav-actions">
Expand Down